[lockfile] add typings for v1, enable strict null checks & linting (#18929)

This commit is contained in:
Dimitri Benin
2017-08-14 19:03:07 +02:00
committed by Mohamed Hegazy
parent d31ee1e675
commit 8464387069
8 changed files with 126 additions and 32 deletions

View File

@@ -1,23 +1,24 @@
// Type definitions for lockfile v0.4.2
// Type definitions for lockfile 1.0
// Project: https://github.com/isaacs/lockfile
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Options {
wait?: number;
pollPeriod?: number;
stale?: number;
retries?: number;
retryWait?: number;
}
export declare function lock(path: string, opts: Options, callback: (err: Error) => void): void;
export declare function lock(path: string, callback: (err: Error) => void): void;
export declare function lockSync(path: string, opts: Options): void;
export function lock(path: string, opts: Options, callback: (err: Error | null) => void): void;
export function lock(path: string, callback: (err: Error | null) => void): void;
export function lockSync(path: string, opts?: Options): void;
export declare function unlock(path: string, callback: (err: Error) => void): void;
export declare function unlockSync(path: string): void;
export function unlock(path: string, callback: (err: Error | null) => void): void;
export function unlockSync(path: string): void;
export declare function check(path: string, opts: Options, callback: (err: Error, isLocked: boolean) => void): void;
export declare function check(path: string, callback: (err: Error, isLocked: boolean) => void): void;
export declare function checkSync(path: string, opts: Options): boolean;
export function check(path: string, opts: Options, callback: (err: Error | null, isLocked: boolean) => void): void;
export function check(path: string, callback: (err: Error | null, isLocked: boolean) => void): void;
export function checkSync(path: string, opts?: Options): boolean;

View File

@@ -1,33 +1,47 @@
import lockfile = require('lockfile');
var bool: boolean;
var num: number;
var path: string;
let bool: boolean;
const num = 1;
const path = '';
var opts: lockfile.Options;
var callback: (err: Error) => {
let opts: lockfile.Options;
const callback = (err: Error) => {};
};
var callback2: (err: Error, isLocked: boolean) => {
};
lockfile.lock(path, {wait: num}, callback);
lockfile.lock(path, {pollPeriod: num}, callback);
lockfile.lock(path, {stale: num}, callback);
lockfile.lock(path, {retries: num}, callback);
lockfile.lock(path, {retryWait: num}, callback);
opts = {
wait: num,
stale: num,
retries: num,
retryWait: num
wait: num,
pollPeriod: num,
stale: num,
retries: num,
retryWait: num
};
lockfile.lock(path, opts, callback);
lockfile.lock(path, callback);
lockfile.lock(path, opts, (err) => {
err; // $ExpectType Error | null
});
lockfile.lock(path, (err) => {
err; // $ExpectType Error | null
});
lockfile.lockSync(path, opts);
lockfile.lockSync(path);
lockfile.unlock(path, callback);;
lockfile.unlock(path, (err) => {
err; // $ExpectType Error | null
});
lockfile.unlockSync(path);
lockfile.check(path, opts, callback2);
lockfile.check(path, callback2);
lockfile.check(path, opts, (err, isLocked) => {
err; // $ExpectType Error | null
isLocked; // $ExpectType boolean
});
lockfile.check(path, (err, isLocked) => {
err; // $ExpectType Error | null
isLocked; // $ExpectType boolean
});
bool = lockfile.checkSync(path, opts);
bool = lockfile.checkSync(path);

View File

@@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
@@ -19,4 +19,4 @@
"index.d.ts",
"lockfile-tests.ts"
]
}
}

View File

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

22
types/lockfile/v0/index.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
// Type definitions for lockfile 0.4
// Project: https://github.com/isaacs/lockfile
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Options {
wait?: number;
stale?: number;
retries?: number;
retryWait?: number;
}
export function lock(path: string, opts: Options, callback: (err: Error) => void): void;
export function lock(path: string, callback: (err: Error) => void): void;
export function lockSync(path: string, opts: Options): void;
export function unlock(path: string, callback: (err: Error) => void): void;
export function unlockSync(path: string): void;
export function check(path: string, opts: Options, callback: (err: Error, isLocked: boolean) => void): void;
export function check(path: string, callback: (err: Error, isLocked: boolean) => void): void;
export function checkSync(path: string, opts: Options): boolean;

View File

@@ -0,0 +1,30 @@
import lockfile = require('lockfile');
let bool: boolean;
const num = 1;
const path = '';
let opts: lockfile.Options;
const callback = (err: Error) => {
};
const callback2 = (err: Error, isLocked: boolean) => {
};
opts = {
wait: num,
stale: num,
retries: num,
retryWait: num
};
lockfile.lock(path, opts, callback);
lockfile.lock(path, callback);
lockfile.lockSync(path, opts);
lockfile.unlock(path, callback);
lockfile.unlockSync(path);
lockfile.check(path, opts, callback2);
lockfile.check(path, callback2);
bool = lockfile.checkSync(path, opts);

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"lockfile": ["lockfile/v0"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"lockfile-tests.ts"
]
}

View File

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