mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
feat: Add setImmediate (#40012)
This commit is contained in:
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
// Type definitions for setimmediate 1.0
|
||||
// Project: https://github.com/yuzujs/setImmediate#readme
|
||||
// Definitions by: ExE Boss <https://github.com/ExE-Boss>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Schedules a macrotask to run after the current events have been processed.
|
||||
*
|
||||
* Unlike microtasks (scheduled using the Node 0.10+ `process.nextTick` API),
|
||||
* where scheduling additional microtasks inside a microtask will cause them
|
||||
* to be run inside the same microtask checkpoint, any macrotasks scheduled
|
||||
* inside a macrotask will not be executed until the next iteration
|
||||
* of the event loop.
|
||||
*
|
||||
* @param callback The macrotask to schedule.
|
||||
* @param args The arguments to pass to the macrotask callback.
|
||||
*
|
||||
* @return The ID of the macrotask, which can be used to abort
|
||||
* the macrotask with `clearImmediate`.
|
||||
*/
|
||||
declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): number;
|
||||
|
||||
/**
|
||||
* Aborts the specified macrotask before it's run.
|
||||
*
|
||||
* @param handle The ID of the macrotask to remove from the macrotask queue.
|
||||
*/
|
||||
declare function clearImmediate(handle: number): void;
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"private": true,
|
||||
"types": "index",
|
||||
"typesVersions": {
|
||||
">=3.1.0-0": {
|
||||
"*": [
|
||||
"ts3.1/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import './index';
|
||||
|
||||
// $ExpectType number
|
||||
const i = setImmediate((...args) => {
|
||||
args; // $ExpectType any[]
|
||||
});
|
||||
|
||||
clearImmediate(i);
|
||||
|
||||
// Errors:
|
||||
setImmediate(); // $ExpectError
|
||||
|
||||
clearImmediate(); // $ExpectError
|
||||
clearImmediate(null); // $ExpectError
|
||||
clearImmediate(undefined); // $ExpectError
|
||||
clearImmediate('string'); // $ExpectError
|
||||
clearImmediate(Symbol.iterator); // $ExpectError
|
||||
clearImmediate(true); // $ExpectError
|
||||
clearImmediate(false); // $ExpectError
|
||||
clearImmediate({}); // $ExpectError
|
||||
clearImmediate(Function); // $ExpectError
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Schedules a macrotask to run after the current events have been processed.
|
||||
*
|
||||
* Unlike microtasks (scheduled using the Node 0.10+ `process.nextTick` API),
|
||||
* where scheduling additional microtasks inside a microtask will cause them
|
||||
* to be run inside the same microtask checkpoint, any macrotasks scheduled
|
||||
* inside a macrotask will not be executed until the next iteration
|
||||
* of the event loop.
|
||||
*
|
||||
* @param callback The macrotask to schedule.
|
||||
* @param args The arguments to pass to the macrotask callback.
|
||||
*
|
||||
* @return The ID of the macrotask, which can be used to abort
|
||||
* the macrotask with `clearImmediate`.
|
||||
*/
|
||||
declare function setImmediate<T extends unknown[]>(callback: (...args: T) => void, ...args: T): number;
|
||||
|
||||
/**
|
||||
* Aborts the specified macrotask before it's run.
|
||||
*
|
||||
* @param handle The ID of the macrotask to remove from the macrotask queue.
|
||||
*/
|
||||
declare function clearImmediate(handle: number): void;
|
||||
@@ -0,0 +1,36 @@
|
||||
import './index';
|
||||
|
||||
// $ExpectType number
|
||||
const i1 = setImmediate((...args) => {
|
||||
args; // $ExpectType []
|
||||
});
|
||||
|
||||
// $ExpectType number
|
||||
const i2 = setImmediate((...args) => {
|
||||
args; // $ExpectType [number]
|
||||
}, 1);
|
||||
|
||||
// $ExpectType number
|
||||
const i3 = setImmediate((foo, bar, baz) => {
|
||||
foo; // $ExpectType number
|
||||
bar; // $ExpectType string
|
||||
baz; // $ExpectType boolean
|
||||
}, 1, 'a', true);
|
||||
|
||||
clearImmediate(i1);
|
||||
clearImmediate(i2);
|
||||
clearImmediate(i3);
|
||||
|
||||
// Errors:
|
||||
setImmediate(); // $ExpectError
|
||||
setImmediate((foo: unknown) => {}); // $ExpectError
|
||||
|
||||
clearImmediate(); // $ExpectError
|
||||
clearImmediate(null); // $ExpectError
|
||||
clearImmediate(undefined); // $ExpectError
|
||||
clearImmediate('string'); // $ExpectError
|
||||
clearImmediate(Symbol.iterator); // $ExpectError
|
||||
clearImmediate(true); // $ExpectError
|
||||
clearImmediate(false); // $ExpectError
|
||||
clearImmediate({}); // $ExpectError
|
||||
clearImmediate(Function); // $ExpectError
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": ["../../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"setimmediate-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"setimmediate-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user