From 45d54e8373a09218afc1c2067aff80e5bd77f676 Mon Sep 17 00:00:00 2001 From: George Zhao Date: Fri, 6 Dec 2019 10:52:30 +1100 Subject: [PATCH 1/2] Add TypeScript typings --- README.md | 12 ++++++++++++ index.d.ts | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 index.d.ts diff --git a/README.md b/README.md index ad7f2ce..f4cef0f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ throw err; Simple usage. ```js +// JavaScript var errcode = require('err-code'); // fill error with message + code @@ -55,6 +56,17 @@ throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional inform throw errcode(new Error('My message'), { detail: 'Additional information about the error' }); ``` +```typescript +// TypeScript +import errcode = require('err-code'); + +// fill error with message + code +throw errcode(new Error('My message'), 'ESOMECODE'); +// fill error with message + code + props +throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' }); +// fill error with message + props +throw errcode(new Error('My message'), { detail: 'Additional information about the error' }); +``` ## Tests diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8b6b651 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,10 @@ +type Scalar = Exclude + +declare function createError(error: E, code: C, props?: T): E & T & { code: C } +declare function createError(error: E, props?: T): E & T + +declare namespace createError { + +} + +export = createError From bf4d51736fe0285115d6c9314bb2293e2552361c Mon Sep 17 00:00:00 2001 From: George Zhao Date: Fri, 6 Dec 2019 11:57:48 +1100 Subject: [PATCH 2/2] Make type order same as parameters order --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 8b6b651..b2ce72a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ type Scalar = Exclude -declare function createError(error: E, code: C, props?: T): E & T & { code: C } +declare function createError(error: E, code: C, props?: T): E & T & { code: C } declare function createError(error: E, props?: T): E & T declare namespace createError {