Merge pull request #31649 from BendingBender/macrotask

[macrotask] Add types
This commit is contained in:
Wesley Wigham
2018-12-24 21:18:28 -08:00
committed by GitHub
4 changed files with 63 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// Type definitions for macrotask 3.0
// Project: https://github.com/calvinmetcalf/macrotask#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
export as namespace macrotask;
export function run<TArgs extends any[]>(
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';
}
+20
View File
@@ -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
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }