From 0f4790a00e307ad9e4b76ab9513225a43149aa64 Mon Sep 17 00:00:00 2001 From: segayuu Date: Tue, 22 May 2018 11:20:17 +0900 Subject: [PATCH 1/4] Create @types/iferr --- types/iferr/iferr-tests.ts | 38 ++++++++++++++++++++++++++++++++++++++ types/iferr/index.d.ts | 29 +++++++++++++++++++++++++++++ types/iferr/tsconfig.json | 16 ++++++++++++++++ types/iferr/tslint.json | 1 + 4 files changed, 84 insertions(+) create mode 100644 types/iferr/iferr-tests.ts create mode 100644 types/iferr/index.d.ts create mode 100644 types/iferr/tsconfig.json create mode 100644 types/iferr/tslint.json diff --git a/types/iferr/iferr-tests.ts b/types/iferr/iferr-tests.ts new file mode 100644 index 0000000000..f7377358cf --- /dev/null +++ b/types/iferr/iferr-tests.ts @@ -0,0 +1,38 @@ +/// + +import * as fs from "fs"; +import iferr = require("iferr"); + +const { tiferr, throwerr, printerr } = iferr; + +const { readFile } = fs; + +const errcb = (err: Error | undefined) => { throw err; }; + +readFile("test.txt", iferr(errcb, result => { + Buffer.from("test", "utf8") === result; +})); + +readFile("test.txt", "utf8", iferr(errcb, result => { + "test" === result; +})); + +readFile("test.txt", tiferr(errcb, result => { + Buffer.from("test", "utf8") === result; +})); + +readFile("test.txt", "utf8", tiferr(errcb, result => { + "test" === result; +})); + +readFile("test.txt", throwerr(result => { + Buffer.from("test", "utf8") === result; +})); + +readFile("test.txt", "utf8", throwerr(result => { + "test" === result; +})); + +readFile("test.txt", printerr); + +readFile("test.txt", "utf8", printerr); diff --git a/types/iferr/index.d.ts b/types/iferr/index.d.ts new file mode 100644 index 0000000000..a330a3455c --- /dev/null +++ b/types/iferr/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for iferr +// Project: https://github.com/shesek/iferr/ +// Definitions by: segayuu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare type nodeCallback = (err: Error | undefined, ...a: T[]) => any; + +// Delegates to `succ` on sucecss or to `fail` on error +// ex: Thing.load(123, iferr(cb, thing => ...)) +declare function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback + +declare namespace iferr { + // Delegates to `succ` on sucecss or to `fail` on error + // ex: Thing.load(123, iferr(cb, thing => ...)) + export function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback + + // Like iferr, but also catches errors thrown from `succ` and passes to `fail` + export function tiferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback + + // Delegate to the success function on success, throws the error otherwise + // ex: Thing.load(123, throwerr(thing => ...)) + export function throwerr(succ: (...result: T[]) => void): nodeCallback + + // Prints errors when one is passed, or does nothing otherwise + // ex: Thing.load(123, printerr) + export function printerr(): nodeCallback; +} + +export = iferr; diff --git a/types/iferr/tsconfig.json b/types/iferr/tsconfig.json new file mode 100644 index 0000000000..5496e49b42 --- /dev/null +++ b/types/iferr/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": ["index.d.ts", "iferr-tests.ts"] +} diff --git a/types/iferr/tslint.json b/types/iferr/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iferr/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 0e76900909c9f128ef78965b5e33cfd83c675e9d Mon Sep 17 00:00:00 2001 From: segayuu Date: Tue, 22 May 2018 11:25:13 +0900 Subject: [PATCH 2/4] fix format --- types/iferr/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/iferr/index.d.ts b/types/iferr/index.d.ts index a330a3455c..740333576d 100644 --- a/types/iferr/index.d.ts +++ b/types/iferr/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for iferr +// Type definitions for iferr 1.0 // Project: https://github.com/shesek/iferr/ // Definitions by: segayuu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,19 +7,19 @@ declare type nodeCallback = (err: Error | undefined, ...a: T[]) => any; // Delegates to `succ` on sucecss or to `fail` on error // ex: Thing.load(123, iferr(cb, thing => ...)) -declare function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback +declare function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; declare namespace iferr { // Delegates to `succ` on sucecss or to `fail` on error // ex: Thing.load(123, iferr(cb, thing => ...)) - export function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback + export function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; // Like iferr, but also catches errors thrown from `succ` and passes to `fail` - export function tiferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback + export function tiferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; // Delegate to the success function on success, throws the error otherwise // ex: Thing.load(123, throwerr(thing => ...)) - export function throwerr(succ: (...result: T[]) => void): nodeCallback + export function throwerr(succ: (...result: T[]) => void): nodeCallback; // Prints errors when one is passed, or does nothing otherwise // ex: Thing.load(123, printerr) From 39ae1c9015a03ca081e8ff25896c5440d78ad60b Mon Sep 17 00:00:00 2001 From: segayuu Date: Tue, 22 May 2018 11:29:19 +0900 Subject: [PATCH 3/4] fix lint: strict-export-declare-modifiers --- types/iferr/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/iferr/index.d.ts b/types/iferr/index.d.ts index 740333576d..367a0e2527 100644 --- a/types/iferr/index.d.ts +++ b/types/iferr/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: segayuu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare type nodeCallback = (err: Error | undefined, ...a: T[]) => any; +type nodeCallback = (err: Error | undefined, ...a: T[]) => any; // Delegates to `succ` on sucecss or to `fail` on error // ex: Thing.load(123, iferr(cb, thing => ...)) @@ -12,18 +12,18 @@ declare function iferr(fail: (err: Error | undefined) => void, succ: (...resu declare namespace iferr { // Delegates to `succ` on sucecss or to `fail` on error // ex: Thing.load(123, iferr(cb, thing => ...)) - export function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; + function iferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; // Like iferr, but also catches errors thrown from `succ` and passes to `fail` - export function tiferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; + function tiferr(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback; // Delegate to the success function on success, throws the error otherwise // ex: Thing.load(123, throwerr(thing => ...)) - export function throwerr(succ: (...result: T[]) => void): nodeCallback; + function throwerr(succ: (...result: T[]) => void): nodeCallback; // Prints errors when one is passed, or does nothing otherwise // ex: Thing.load(123, printerr) - export function printerr(): nodeCallback; + function printerr(): nodeCallback; } export = iferr; From 2025c31a923c7de26e3a0f370d2c4d0f51163616 Mon Sep 17 00:00:00 2001 From: segayuu Date: Tue, 22 May 2018 11:41:47 +0900 Subject: [PATCH 4/4] fix format from dts-gen --- types/iferr/index.d.ts | 2 +- types/iferr/tsconfig.json | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/types/iferr/index.d.ts b/types/iferr/index.d.ts index 367a0e2527..c65c270b49 100644 --- a/types/iferr/index.d.ts +++ b/types/iferr/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for iferr 1.0 -// Project: https://github.com/shesek/iferr/ +// Project: https://github.com/shesek/iferr // Definitions by: segayuu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/iferr/tsconfig.json b/types/iferr/tsconfig.json index 5496e49b42..db97bdf495 100644 --- a/types/iferr/tsconfig.json +++ b/types/iferr/tsconfig.json @@ -1,16 +1,23 @@ { "compilerOptions": { "module": "commonjs", - "lib": ["es6"], + "lib": [ + "es6" + ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", - "typeRoots": ["../"], + "typeRoots": [ + "../" + ], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true, "strictFunctionTypes": true }, - "files": ["index.d.ts", "iferr-tests.ts"] + "files": [ + "index.d.ts", + "iferr-tests.ts" + ] }