mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
[safe-timers] Add definitions (#41454)
* Add safe-timers definitions * Remove not public api, add comments
This commit is contained in:
committed by
Armando Aguirre
parent
a33919717d
commit
6e560d4643
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
// Type definitions for safe-timers 1.1
|
||||
// Project: https://github.com/Wizcorp/safe-timers#readme
|
||||
// Definitions by: Kamil Socha <https://github.com/ksocha>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
export const maxInterval: number;
|
||||
|
||||
export class Timeout {
|
||||
/**
|
||||
* Cancels timeout.
|
||||
*/
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a `Timeout` instance that will call `callback` after at least `interval` milliseconds have passed.
|
||||
* All arguments passed after the `interval` will be passed to the `callback` once it gets invoked.
|
||||
*/
|
||||
export function setTimeout<T extends any[]>(callback: (...args: T) => void, interval: number, ...args: T): Timeout;
|
||||
|
||||
/**
|
||||
* Creates and returns a `Timeout` instance that will call `callback` when our clock reaches the given `timestamp` (in milliseconds).
|
||||
* All arguments passed after the `timestamp` will be passed to the `callback` once it gets invoked.
|
||||
*/
|
||||
export function setTimeoutAt<T extends any[]>(callback: (...args: T) => void, timestamp: number, ...args: T): Timeout;
|
||||
|
||||
/**
|
||||
* Cancels `timeout`.
|
||||
*/
|
||||
export function clearTimeout(timeout: Timeout): void;
|
||||
|
||||
export class Interval {
|
||||
/**
|
||||
* Cancels interval.
|
||||
*/
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an `Interval` instance that will call `callback` after at least every `interval` milliseconds.
|
||||
* All arguments passed after the `interval` will be passed to the `callback` when it gets invoked.
|
||||
*/
|
||||
export function setInterval<T extends any[]>(callback: (...args: T) => void, interval: number, ...args: T): Interval;
|
||||
|
||||
/**
|
||||
* Cancels `interval`.
|
||||
*/
|
||||
export function clearInterval(interval: Interval): void;
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
maxInterval,
|
||||
Timeout,
|
||||
setTimeout,
|
||||
setTimeoutAt,
|
||||
clearTimeout,
|
||||
Interval,
|
||||
setInterval,
|
||||
clearInterval,
|
||||
} from 'safe-timers';
|
||||
|
||||
const maxIntervalTest: number = maxInterval;
|
||||
|
||||
const timeout: Timeout = setTimeout(() => {}, 1000);
|
||||
const timeoutWithArgs: Timeout = setTimeout((hero: string, powerLevel: number) => {}, 1000, 'Goku', 9000);
|
||||
|
||||
const timeoutAt: Timeout = setTimeoutAt(() => {}, 1000);
|
||||
const timeoutAtWithArgs: Timeout = setTimeoutAt((hero: string, powerLevel: number) => {}, 1000, 'Goku', 9000);
|
||||
|
||||
timeout.clear();
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
const interval: Interval = setInterval(() => {}, 1000);
|
||||
const intervalWithArgs: Interval = setInterval((hero: string, powerLevel: number) => {}, 1000, 'Goku', 9000);
|
||||
|
||||
interval.clear();
|
||||
|
||||
clearInterval(interval);
|
||||
@@ -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",
|
||||
"safe-timers-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user