From 6d7624e50fcad42e22a1cfddcea4bc7fa03bc29d Mon Sep 17 00:00:00 2001 From: Dominik Rowicki Date: Wed, 2 Oct 2019 22:56:23 +0200 Subject: [PATCH] Create definition for just-throttle (#38707) * Create definition for just-throttle * Use more specific URL for the project * Improve comments in tests slightly --- types/just-throttle/index.d.ts | 10 ++++++++++ types/just-throttle/just-throttle-tests.ts | 11 +++++++++++ types/just-throttle/tsconfig.json | 23 ++++++++++++++++++++++ types/just-throttle/tslint.json | 1 + 4 files changed, 45 insertions(+) create mode 100644 types/just-throttle/index.d.ts create mode 100644 types/just-throttle/just-throttle-tests.ts create mode 100644 types/just-throttle/tsconfig.json create mode 100644 types/just-throttle/tslint.json diff --git a/types/just-throttle/index.d.ts b/types/just-throttle/index.d.ts new file mode 100644 index 0000000000..8dd9cee52a --- /dev/null +++ b/types/just-throttle/index.d.ts @@ -0,0 +1,10 @@ +// Type definitions for just-throttle 1.1 +// Project: https://github.com/angus-c/just/tree/master/packages/function-throttle +// Definitions by: Dominik Rowicki +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +declare function throttle(fn: (...args: unknown[]) => unknown, interval: number, callFirst?: false): () => void; +declare function throttle(fn: T, interval: number, callFirst?: true): T; + +export = throttle; diff --git a/types/just-throttle/just-throttle-tests.ts b/types/just-throttle/just-throttle-tests.ts new file mode 100644 index 0000000000..1a3bfd0daf --- /dev/null +++ b/types/just-throttle/just-throttle-tests.ts @@ -0,0 +1,11 @@ +import throttle = require('just-throttle'); + +// returns a function that sets an interval but doesn't do anything else by +// default +throttle(() => 'foo', 200); // $ExpectType () => void +throttle(() => 'foo', 200, false); // $ExpectType () => void + +// if third argument is true, the returned function will immediately apply the +// callback when called +throttle(() => 'foo', 200, true); // $ExpectType () => string +throttle((foo: string) => 42, 200, true); // $ExpectType (foo: string) => number diff --git a/types/just-throttle/tsconfig.json b/types/just-throttle/tsconfig.json new file mode 100644 index 0000000000..778d43621a --- /dev/null +++ b/types/just-throttle/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", + "just-throttle-tests.ts" + ] +} diff --git a/types/just-throttle/tslint.json b/types/just-throttle/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/just-throttle/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }