mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-30 17:04:20 +08:00
once
This commit is contained in:
13
once/once-tests.ts
Normal file
13
once/once-tests.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/// <reference path="once.d.ts" />
|
||||
|
||||
import once from "once";
|
||||
|
||||
once(() => 3);
|
||||
once(() => 3)();
|
||||
let s = once(() => ({foo: 1}))();
|
||||
s.foo;
|
||||
|
||||
once.proto();
|
||||
|
||||
once(() => 3).called && true;
|
||||
once(() => ({foo: 1})).value.foo;
|
||||
23
once/once.d.ts
vendored
Normal file
23
once/once.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Type definitions for once v1.3.3
|
||||
// Project: https://github.com/isaacs/once
|
||||
// Definitions by: Denis Sokolov <https://github.com/denis-sokolov>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface SimpleFunction<Result> {
|
||||
(...args: any[]): Result;
|
||||
}
|
||||
|
||||
interface OnceFunction<Result> extends SimpleFunction<Result> {
|
||||
called: boolean;
|
||||
value: Result;
|
||||
}
|
||||
|
||||
interface Once {
|
||||
<Result>(f: SimpleFunction<Result>): OnceFunction<Result>;
|
||||
proto: Function;
|
||||
}
|
||||
|
||||
declare module "once" {
|
||||
var once: Once;
|
||||
export default once;
|
||||
}
|
||||
Reference in New Issue
Block a user