diff --git a/types/tti-polyfill/index.d.ts b/types/tti-polyfill/index.d.ts new file mode 100644 index 0000000000..864b5ec8fa --- /dev/null +++ b/types/tti-polyfill/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for tti-polyfill 0.2 +// Project: https://github.com/GoogleChrome/tti-polyfill#readme +// Definitions by: Patrick Weygand +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/*~ If this module is a UMD module that exposes a global variable 'myLib' when + *~ loaded outside a module loader environment, declare that global here. + *~ Otherwise, delete this declaration. + */ +export as namespace ttiPolyfill; + +/** + * Returns a promise that resolves to the first consistently interactive time + * (in milliseconds) or null if the browser doesn't support the features + * required for detection. + * ``` + * ttiPolyfill.getFirstConsistentlyInteractive(opts).then((tti) => { + * // Use `tti` value in some way. + * }); + * ``` + * @param opts Configuration options for + * the polyfill + * @return a promise that resolves to TTI + */ +export function getFirstConsistentlyInteractive(opts?: GetFirstConsistentlyInteractiveOpts): Promise; + +export interface GetFirstConsistentlyInteractiveOpts { + /** + * When true (the default), a mutation observer is used to detect when added + * DOM elements will create additional network requests. This can be + * disabled to improve performance in cases where you know no additional + * request-creating DOM elements will be added. + */ + useMutationObserver?: boolean; + /** + * The lower bound to start forward-searching for the quite window. If no value is set, the default is after the + * DOMContentLoaded event. + */ + minValue?: number | null; +} diff --git a/types/tti-polyfill/tsconfig.json b/types/tti-polyfill/tsconfig.json new file mode 100644 index 0000000000..3781258152 --- /dev/null +++ b/types/tti-polyfill/tsconfig.json @@ -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", + "tti-polyfill-tests.ts" + ] +} diff --git a/types/tti-polyfill/tslint.json b/types/tti-polyfill/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tti-polyfill/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/tti-polyfill/tti-polyfill-tests.ts b/types/tti-polyfill/tti-polyfill-tests.ts new file mode 100644 index 0000000000..21305dc65f --- /dev/null +++ b/types/tti-polyfill/tti-polyfill-tests.ts @@ -0,0 +1,3 @@ +import { getFirstConsistentlyInteractive } from 'tti-polyfill'; + +getFirstConsistentlyInteractive(); // $ExpectType Promise