mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-03-03 05:02:48 +00:00
[onetime] Update types to v3.0
This commit is contained in:
parent
c5c72bcb9b
commit
2347afcc47
45
types/onetime/index.d.ts
vendored
Normal file
45
types/onetime/index.d.ts
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Type definitions for onetime 3.0
|
||||
// Project: https://github.com/sindresorhus/onetime#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
export = oneTime;
|
||||
|
||||
/**
|
||||
* Ensure a function is only called once. When called multiple times it will return the return value from the first call.
|
||||
*
|
||||
* @param fn Function that should only be called once.
|
||||
* @returns A function that only calls `fn` once.
|
||||
*/
|
||||
declare function oneTime<T extends any[], R>(
|
||||
fn: (...args: T) => R,
|
||||
options?: oneTime.Options
|
||||
): (...args: T) => R;
|
||||
|
||||
declare namespace oneTime {
|
||||
/**
|
||||
* Get the number of times `fn` has been called.
|
||||
*
|
||||
* @param fn Function to get call count from.
|
||||
* @returns A number representing how many times `fn` has been called.
|
||||
*
|
||||
* @example
|
||||
* const foo = onetime(() => {});
|
||||
* foo();
|
||||
* foo();
|
||||
* foo();
|
||||
*
|
||||
* console.log(onetime.callCount(foo));
|
||||
* //=> 3
|
||||
*/
|
||||
function callCount(fn: (...args: any[]) => any): number | undefined;
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* Throw an error when called more than once.
|
||||
* @default false
|
||||
*/
|
||||
throw?: boolean;
|
||||
}
|
||||
}
|
||||
12
types/onetime/onetime-tests.ts
Normal file
12
types/onetime/onetime-tests.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import onetime = require('onetime');
|
||||
|
||||
const foo = onetime(() => 5);
|
||||
foo(); // $ExpectType number
|
||||
|
||||
const foo2 = onetime(() => true, { throw: true });
|
||||
foo2(); // $ExpectType boolean
|
||||
|
||||
onetime((t1: boolean) => 5)(true); // $ExpectType number
|
||||
onetime((t1: boolean, t2: string) => 5)(true, ''); // $ExpectType number
|
||||
|
||||
onetime.callCount((t1: boolean, t2: string) => 5); // $ExpectType number | undefined
|
||||
23
types/onetime/tsconfig.json
Normal file
23
types/onetime/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"onetime-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/onetime/tslint.json
Normal file
1
types/onetime/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user