[estimate] New types (#38904)

This commit is contained in:
Luís Rodrigues 2019-10-09 00:36:02 +01:00 committed by Armando Aguirre
parent 098cceb6d0
commit ce338b4fd0
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,28 @@
import { element, text } from 'estimate';
function assertType<T>(value: T): T {
return value;
}
element(document.body);
element(document.createElement('article'));
element(document.createElement('article'), {});
const estimate = element(document.createElement('article'), {
speed: 300,
spaces: /\W+/g,
});
assertType<number>(estimate.progress);
assertType<number>(estimate.remaining);
assertType<number>(estimate.total);
estimate.update();
estimate.initialize();
text('text');
text('text', {});
text('text', {
speed: 300,
spaces: /\W+/g,
});
assertType<number>(text('text'));

21
types/estimate/index.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
// Type definitions for estimate 1.0
// Project: https://github.com/bevacqua/estimate
// Definitions by: Luis Rodrigues <https://github.com/goblindegook>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Options {
speed?: number;
spaces?: RegExp;
}
export interface Estimate {
progress: number;
remaining: number;
total: number;
update(): void;
initialize(): void;
}
export function element(element: HTMLElement, options?: Options): Estimate;
export function text(text: string, options?: Options): number;

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6", "dom"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "estimate-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }