[slocket] add typings

This commit is contained in:
Dimitri Benin
2017-08-22 10:04:07 +02:00
parent cf0172024a
commit 6890c59462
4 changed files with 80 additions and 0 deletions

30
types/slocket/index.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for slocket 1.0
// Project: https://github.com/isaacs/slocket#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
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<TResult1 = Lock, TResult2 = never>(
onfulfilled?: ((value: Lock) => TResult1 | PromiseLike<TResult1>) | undefined | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<Lock | TResult>;
}
interface Lock {
release(sync?: boolean): void;
}
}

View File

@@ -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()
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }