Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript typings #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ throw err;
Simple usage.

```js
// JavaScript
var errcode = require('err-code');

// fill error with message + code
Expand All @@ -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

Expand Down
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Scalar = Exclude<any, object>

declare function createError<E extends Error, C extends Scalar, T extends object>(error: E, code: C, props?: T): E & T & { code: C }
declare function createError<E extends Error, T extends object>(error: E, props?: T): E & T

declare namespace createError {

}

export = createError