Merge pull request #19231 from BendingBender/slocket

[slocket] add typings
This commit is contained in:
Daniel Rosenwasser
2017-08-22 09:59:36 -07:00
committed by GitHub
4 changed files with 80 additions and 0 deletions
+30
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;
}
}
+27
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()
}
+22
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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }