From c7a768fca6510f402c60d7a74a9a568fd29bd68f Mon Sep 17 00:00:00 2001 From: Matthias Kunnen Date: Thu, 13 Aug 2020 01:38:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#46642=20feat(long-?= =?UTF-8?q?timeout):=20new=20type=20definition=20by=20@MatthiasKunnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(long-timeout): new type definition * fix(long-timeout): remove export as namespace long-timeout does not have a UMD wrapper. --- types/long-timeout/index.d.ts | 28 ++++++++++++++++++++++++ types/long-timeout/long-timeout-tests.ts | 15 +++++++++++++ types/long-timeout/tsconfig.json | 23 +++++++++++++++++++ types/long-timeout/tslint.json | 1 + 4 files changed, 67 insertions(+) create mode 100644 types/long-timeout/index.d.ts create mode 100644 types/long-timeout/long-timeout-tests.ts create mode 100644 types/long-timeout/tsconfig.json create mode 100644 types/long-timeout/tslint.json diff --git a/types/long-timeout/index.d.ts b/types/long-timeout/index.d.ts new file mode 100644 index 0000000000..ae82ec84f1 --- /dev/null +++ b/types/long-timeout/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for long-timeout 0.1 +// Project: https://github.com/tellnes/long-timeout +// Definitions by: Matthias Kunnen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type Listener = (...args: any[]) => void; + +export class Timeout { + after: number; + close: () => void; + listener: Listener; + ref: () => void; + start: () => void; + unref: () => void; + unreffed: boolean; + + constructor(listener: Listener, ms: number); +} + +export type Interval = Timeout; + +export function clearInterval(timer: Interval): void; + +export function clearTimeout(timer: Timeout): void; + +export function setInterval(listener: Listener, ms: number): Interval; + +export function setTimeout(listener: Listener, ms: number): Timeout; diff --git a/types/long-timeout/long-timeout-tests.ts b/types/long-timeout/long-timeout-tests.ts new file mode 100644 index 0000000000..4395722f2d --- /dev/null +++ b/types/long-timeout/long-timeout-tests.ts @@ -0,0 +1,15 @@ +import * as lt from 'long-timeout'; + +const interval = lt.setInterval(() => { + // Do things +}, 4000); + +interval.close(); + +lt.clearInterval(interval); + +const timeout = lt.setTimeout(() => { + // Do things +}, 50); + +lt.clearTimeout(timeout); diff --git a/types/long-timeout/tsconfig.json b/types/long-timeout/tsconfig.json new file mode 100644 index 0000000000..8773438f14 --- /dev/null +++ b/types/long-timeout/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "long-timeout-tests.ts" + ] +} diff --git a/types/long-timeout/tslint.json b/types/long-timeout/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/long-timeout/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }