Skip to content

Commit 4926126

Browse files
committed
feat(types): NodeError
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 9494c4c commit 4926126

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file Unit Tests - NodeError
3+
* @module create-node-error/types/tests/unit-d/NodeError
4+
*/
5+
6+
import type { ErrorCode } from '#src/enums'
7+
import type TestSubject from '../node-error'
8+
9+
describe('unit-d:types/NodeError', () => {
10+
it('should have type param extend Error type', () => {
11+
expectTypeOf<TestSubject>().toMatchTypeOf<Error>()
12+
expectTypeOf<TestSubject<RangeError>>().toMatchTypeOf<RangeError>()
13+
expectTypeOf<TestSubject<TypeError>>().toMatchTypeOf<TypeError>()
14+
})
15+
16+
it('should match [code: ErrorCode]', () => {
17+
expectTypeOf<TestSubject>()
18+
.toHaveProperty('code')
19+
.toEqualTypeOf<ErrorCode>()
20+
})
21+
})

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*/
55

66
export type { default as MessageFn } from './fn-message'
7+
export type { default as NodeError } from './node-error'

src/types/node-error.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @file Type Definitions - NodeError
3+
* @module create-node-error/types/NodeError
4+
*/
5+
6+
import type { ErrorCode } from '#src/enums'
7+
8+
/**
9+
* Node.js error.
10+
*
11+
* @template T - Error base type
12+
*
13+
* @extends {T}
14+
*/
15+
type NodeError<T extends Error = Error> = T & {
16+
/**
17+
* Error code.
18+
*/
19+
code: ErrorCode
20+
}
21+
22+
export type { NodeError as default }

0 commit comments

Comments
 (0)