Skip to content

Commit

Permalink
docs(readme): add typescript example (#105)
Browse files Browse the repository at this point in the history
* typescript readme

* update

* Update README.md

Co-authored-by: Frazer Smith <[email protected]>

---------

Co-authored-by: Frazer Smith <[email protected]>
  • Loading branch information
trim21 and Fdawgs authored Jun 2, 2023
1 parent b58dbcf commit 80f3335
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world')) // error.message => 'Hello world'
```

### TypeScript

It is possible to limit your error constructor with a generic type using TypeScript:

```ts
const CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')
new CustomError('world')
//@ts-expect-error
new CustomError(1)
//@ts-expect-error
new CustomError(1)
```

## License

Licensed under [MIT](./LICENSE).

0 comments on commit 80f3335

Please sign in to comment.