From 67ea9ab52c90bfecbc31ea262cf918e485f345a6 Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Thu, 28 Jan 2016 11:02:31 +0200 Subject: [PATCH] once --- once/once-tests.ts | 13 +++++++++++++ once/once.d.ts | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 once/once-tests.ts create mode 100644 once/once.d.ts diff --git a/once/once-tests.ts b/once/once-tests.ts new file mode 100644 index 0000000000..05f60f0400 --- /dev/null +++ b/once/once-tests.ts @@ -0,0 +1,13 @@ +/// + +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; diff --git a/once/once.d.ts b/once/once.d.ts new file mode 100644 index 0000000000..a0aa60e798 --- /dev/null +++ b/once/once.d.ts @@ -0,0 +1,23 @@ +// Type definitions for once v1.3.3 +// Project: https://github.com/isaacs/once +// Definitions by: Denis Sokolov +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface SimpleFunction { + (...args: any[]): Result; +} + +interface OnceFunction extends SimpleFunction { + called: boolean; + value: Result; +} + +interface Once { + (f: SimpleFunction): OnceFunction; + proto: Function; +} + +declare module "once" { + var once: Once; + export default once; +}