From 17fe8bd618e4a33c3c948f6d9e065e6ed5687a7b Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 24 Dec 2018 18:33:37 +0100 Subject: [PATCH] [macrotask] Add types --- types/macrotask/index.d.ts | 19 +++++++++++++++++++ types/macrotask/macrotask-tests.ts | 20 ++++++++++++++++++++ types/macrotask/tsconfig.json | 23 +++++++++++++++++++++++ types/macrotask/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/macrotask/index.d.ts create mode 100644 types/macrotask/macrotask-tests.ts create mode 100644 types/macrotask/tsconfig.json create mode 100644 types/macrotask/tslint.json diff --git a/types/macrotask/index.d.ts b/types/macrotask/index.d.ts new file mode 100644 index 0000000000..5169d0d475 --- /dev/null +++ b/types/macrotask/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for macrotask 3.0 +// Project: https://github.com/calvinmetcalf/macrotask#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +export as namespace macrotask; + +export function run( + task: (...args: TArgs) => void, + ...args: TArgs +): CancelToken; + +export function clear(cancel: CancelToken): void; + +export class CancelToken { + // needed for TS to not accept just any object, only instances of CancelToken + private __cancel__prop: 'imaginary'; +} diff --git a/types/macrotask/macrotask-tests.ts b/types/macrotask/macrotask-tests.ts new file mode 100644 index 0000000000..ca69e37f41 --- /dev/null +++ b/types/macrotask/macrotask-tests.ts @@ -0,0 +1,20 @@ +import { run, clear } from 'macrotask'; + +const token = run(() => {}); +run(arg1 => {}); // $ExpectError + +run( + (arg1, arg2) => { + arg1; // $ExpectType string + arg2; // $ExpectType number + }, + 'foo', + 1 +); +// $ExpectError +run((arg1, arg2) => {}, 'foo'); +// $ExpectError +run((arg1: string, arg2: number) => {}, 'foo', 'bar'); + +clear(token); +clear({}); // $ExpectError diff --git a/types/macrotask/tsconfig.json b/types/macrotask/tsconfig.json new file mode 100644 index 0000000000..7d6e0f6fcb --- /dev/null +++ b/types/macrotask/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "macrotask-tests.ts" + ] +} diff --git a/types/macrotask/tslint.json b/types/macrotask/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/macrotask/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }