mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
[slocket] add typings
This commit is contained in:
30
types/slocket/index.d.ts
vendored
Normal file
30
types/slocket/index.d.ts
vendored
Normal 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
types/slocket/slocket-tests.ts
Normal file
27
types/slocket/slocket-tests.ts
Normal 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
types/slocket/tsconfig.json
Normal file
22
types/slocket/tsconfig.json
Normal 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
types/slocket/tslint.json
Normal file
1
types/slocket/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user