Skip to content

Commit d14d57c

Browse files
derduhersheetalkamat
authored andcommitted
Add typings for tti-polyfill (DefinitelyTyped#37731)
* Add typings for tti-polyfill * fix minValue definition
1 parent 21a2f12 commit d14d57c

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

types/tti-polyfill/index.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Type definitions for tti-polyfill 0.2
2+
// Project: https://github.com/GoogleChrome/tti-polyfill#readme
3+
// Definitions by: Patrick Weygand <https://github.com/derduher>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
/*~ If this module is a UMD module that exposes a global variable 'myLib' when
7+
*~ loaded outside a module loader environment, declare that global here.
8+
*~ Otherwise, delete this declaration.
9+
*/
10+
export as namespace ttiPolyfill;
11+
12+
/**
13+
* Returns a promise that resolves to the first consistently interactive time
14+
* (in milliseconds) or null if the browser doesn't support the features
15+
* required for detection.
16+
* ```
17+
* ttiPolyfill.getFirstConsistentlyInteractive(opts).then((tti) => {
18+
* // Use `tti` value in some way.
19+
* });
20+
* ```
21+
* @param opts Configuration options for
22+
* the polyfill
23+
* @return a promise that resolves to TTI
24+
*/
25+
export function getFirstConsistentlyInteractive(opts?: GetFirstConsistentlyInteractiveOpts): Promise<number|null>;
26+
27+
export interface GetFirstConsistentlyInteractiveOpts {
28+
/**
29+
* When true (the default), a mutation observer is used to detect when added
30+
* DOM elements will create additional network requests. This can be
31+
* disabled to improve performance in cases where you know no additional
32+
* request-creating DOM elements will be added.
33+
*/
34+
useMutationObserver?: boolean;
35+
/**
36+
* The lower bound to start forward-searching for the quite window. If no value is set, the default is after the
37+
* DOMContentLoaded event.
38+
*/
39+
minValue?: number | null;
40+
}

types/tti-polyfill/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"tti-polyfill-tests.ts"
22+
]
23+
}

types/tti-polyfill/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { getFirstConsistentlyInteractive } from 'tti-polyfill';
2+
3+
getFirstConsistentlyInteractive(); // $ExpectType Promise<number | null>

0 commit comments

Comments
 (0)