Skip to content

Commit 80f3335

Browse files
trim21Fdawgs
andauthored
docs(readme): add typescript example (#105)
* typescript readme * update * Update README.md Co-authored-by: Frazer Smith <frazer.dev@outlook.com> --------- Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
1 parent b58dbcf commit 80f3335

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ const CustomError = createError('ERROR_CODE', 'Hello %s')
3737
console.log(new CustomError('world')) // error.message => 'Hello world'
3838
```
3939

40+
### TypeScript
41+
42+
It is possible to limit your error constructor with a generic type using TypeScript:
43+
44+
```ts
45+
const CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')
46+
new CustomError('world')
47+
//@ts-expect-error
48+
new CustomError(1)
49+
//@ts-expect-error
50+
new CustomError(1)
51+
```
52+
4053
## License
4154

4255
Licensed under [MIT](./LICENSE).

0 commit comments

Comments
 (0)