From 6890c59462e77d041f41a0b9cf770e062a74ada3 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 22 Aug 2017 10:04:07 +0200 Subject: [PATCH] [slocket] add typings --- types/slocket/index.d.ts | 30 ++++++++++++++++++++++++++++++ types/slocket/slocket-tests.ts | 27 +++++++++++++++++++++++++++ types/slocket/tsconfig.json | 22 ++++++++++++++++++++++ types/slocket/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/slocket/index.d.ts create mode 100644 types/slocket/slocket-tests.ts create mode 100644 types/slocket/tsconfig.json create mode 100644 types/slocket/tslint.json diff --git a/types/slocket/index.d.ts b/types/slocket/index.d.ts new file mode 100644 index 0000000000..a33ab9ffd8 --- /dev/null +++ b/types/slocket/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for slocket 1.0 +// Project: https://github.com/isaacs/slocket#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// +import { EventEmitter } from 'events'; + +export = slocket; + +declare const slocket: Slocket; + +interface Slocket { + (lockFile: string, cb?: (error: Error | null, lock: slocket.Lock) => void): slocket.Slocket; + new (lockFile: string, cb?: (error: Error | null, lock: slocket.Lock) => void): slocket.Slocket; +} + +declare namespace slocket { + interface Slocket extends EventEmitter { + then( + onfulfilled?: ((value: Lock) => TResult1 | PromiseLike) | undefined | null, + onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): Promise; + catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; + } + + interface Lock { + release(sync?: boolean): void; + } +} diff --git a/types/slocket/slocket-tests.ts b/types/slocket/slocket-tests.ts new file mode 100644 index 0000000000..f811ebc9aa --- /dev/null +++ b/types/slocket/slocket-tests.ts @@ -0,0 +1,27 @@ +import slocket = require('slocket'); + +function someMutexedThing() { + slocket('/path/to/my-lock-name', (er, lock) => { + er; // $ExpectType Error | null + lock; // $ExpectType Lock + if (er) { + throw er; + } + + lock.release(); + lock.release(true); + }); +} + +slocket('/path/to/filename.lock') + .then(lock => { + lock; // $ExpectType Lock + lock.release(); + }) + .catch(er => { + }); + +async function fooSingleFile () { + const lock = await slocket('foo'); + lock.release() +} diff --git a/types/slocket/tsconfig.json b/types/slocket/tsconfig.json new file mode 100644 index 0000000000..16d8617844 --- /dev/null +++ b/types/slocket/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "slocket-tests.ts" + ] +} diff --git a/types/slocket/tslint.json b/types/slocket/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/slocket/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }