Added window interface and tests to requestidlecallback: Part 2 (#38124)

* added tests and updated requestidlecallback type

* added tests and updated requestidlecallback type

* - corrected arguments according to feedback.
This commit is contained in:
Max Boguslavsky
2019-09-23 15:37:12 -07:00
committed by Ben Lichtman
parent 6d08375709
commit 1e76cc036f
3 changed files with 25 additions and 2 deletions
+6 -1
View File
@@ -1,6 +1,6 @@
// Type definitions for requestidlecallback 0.1
// Project: https://w3c.github.io/requestidlecallback/, https://github.com/afarkas/requestidlecallback
// Definitions by: 贺师俊 <https://github.com/hax>
// Definitions by: 贺师俊 <https://github.com/hax>, Vladimir Grenaderov <https://github.com/VladimirGrenaderov>, Max Boguslavskiy <https://github.com/maxbogus>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): IdleCallbackHandle;
@@ -19,3 +19,8 @@ export interface IdleDeadline {
export interface IdleRequestOptions {
timeout: number;
}
export interface Window {
requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): IdleCallbackHandle;
cancelIdleCallback(handle: number): void;
}
@@ -0,0 +1,17 @@
import {
requestIdleCallback,
cancelIdleCallback,
IdleRequestOptions,
IdleCallbackHandle,
} from 'requestidlecallback';
// Test requestIdleCallback with default param
requestIdleCallback(() => '1');
// Test requestIdleCallback with default param and optional param
const option: IdleRequestOptions = { timeout: 2000 };
requestIdleCallback(() => '2', option);
// Test cancelIdleCallback with default param
const handle: IdleCallbackHandle = 1;
cancelIdleCallback(handle);
+2 -1
View File
@@ -17,6 +17,7 @@
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
"index.d.ts",
"requestidlecallback-tests.ts"
]
}