Add touch type definition (#11555)

This commit is contained in:
Mizunashi Mana 2016-10-04 07:57:46 +09:00 committed by Mohamed Hegazy
parent 6054473c85
commit 27d05885ad
3 changed files with 94 additions and 0 deletions

31
touch/index.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Type definitions for touch
// Project: https://github.com/isaacs/node-touch
// Definitions by: Mizunashi Mana <https://github.com/mizunashi-mana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function touch(filename: string, cb: (err: any) => any): void;
declare function touch(filename: string, opts: touch.Options, cb: (err: any) => any): void;
declare namespace touch {
export interface Options {
force?: boolean;
time?: Date | string | number;
atime?: boolean | Date;
mtime?: boolean | Date;
ref?: string;
nocreate?: boolean;
}
export function sync(filename: string, opts?: touch.Options): void;
export function ftouch(fd: number, cb: (err: any) => any): void;
export function ftouch(fd: number, opts: touch.Options, cb: (err: any) => any): void;
export namespace ftouch {
export function sync(fd: number, opts?: touch.Options): void;
}
export const ftouchSync: typeof ftouch.sync;
}
export = touch;

44
touch/touch-tests.ts Normal file
View File

@ -0,0 +1,44 @@
import * as touch from 'touch';
// type value definitions
const boolVal = true;
const numVal = 0;
const strVal = "string";
const dateVal = new Date();
// Options tests
let opts: touch.Options = {};
opts.force = boolVal;
opts.time = numVal;
opts.time = strVal;
opts.time = dateVal;
opts.atime = boolVal;
opts.atime = dateVal;
opts.mtime = boolVal;
opts.mtime = dateVal;
opts.ref = strVal;
opts.nocreate = boolVal;
// touch API tests
touch(strVal, (e) => console.log(e));
touch(strVal, opts, (e) => console.log(e));
touch.sync(strVal);
touch.sync(strVal, opts);
// ftouch API tests
touch.ftouch(numVal, (e) => console.log(e));
touch.ftouch(numVal, opts, (e) => console.log(e));
touch.ftouch.sync(numVal);
touch.ftouch.sync(numVal, opts);
touch.ftouchSync(numVal);
touch.ftouchSync(numVal, opts);

19
touch/tsconfig.json Normal file
View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"touch-tests.ts"
]
}