File tree Expand file tree Collapse file tree 4 files changed +60
-1
lines changed
Expand file tree Collapse file tree 4 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 6464 "typecheck:watch" : " vitest typecheck"
6565 },
6666 "dependencies" : {
67+ "@flex-development/tutils" : " 6.0.0-alpha.7" ,
6768 "node-inspect-extracted" : " 2.0.0"
6869 },
6970 "devDependencies" : {
7273 "@commitlint/types" : " 17.0.0" ,
7374 "@faker-js/faker" : " 7.6.0" ,
7475 "@flex-development/mkbuild" : " 1.0.0-alpha.9" ,
75- "@flex-development/tutils" : " 6.0.0-alpha.7" ,
7676 "@graphql-eslint/eslint-plugin" : " 3.13.0" ,
7777 "@types/chai" : " 4.3.4" ,
7878 "@types/chai-string" : " 1.4.2" ,
Original file line number Diff line number Diff line change 1+ /**
2+ * @file Unit Tests - NodeErrorConstructor
3+ * @module create-node-error/types/tests/unit-d/NodeErrorConstructor
4+ */
5+
6+ import type NodeError from '../node-error'
7+ import type TestSubject from '../node-error-constructor'
8+
9+ describe ( 'unit-d:types/NodeErrorConstructor' , ( ) => {
10+ it ( 'should extract parameters of type any[] if M extends string' , ( ) => {
11+ expectTypeOf < TestSubject > ( ) . parameters . toEqualTypeOf < any [ ] > ( )
12+ expectTypeOf < TestSubject > ( ) . constructorParameters . toEqualTypeOf < any [ ] > ( )
13+ } )
14+
15+ it ( 'should extract parameters of type Parameters<M> if M extends MessageFn' , ( ) => {
16+ type B = TypeErrorConstructor
17+ type M = ( ext : string , path : string ) => string
18+ type P = Parameters < M >
19+
20+ expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < P > ( )
21+ expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < P > ( )
22+ } )
23+
24+ it ( 'should return NodeError<T>' , ( ) => {
25+ expectTypeOf < TestSubject > ( ) . returns . toEqualTypeOf < NodeError > ( )
26+ expectTypeOf < TestSubject < TypeErrorConstructor > > ( ) . returns . toEqualTypeOf <
27+ NodeError < TypeError >
28+ > ( )
29+ } )
30+ } )
Original file line number Diff line number Diff line change 55
66export type { default as MessageFn } from './fn-message'
77export type { default as NodeError } from './node-error'
8+ export type { default as NodeErrorConstructor } from './node-error-constructor'
Original file line number Diff line number Diff line change 1+ /**
2+ * @file Type Definitions - NodeErrorConstructor
3+ * @module create-node-error/types/NodeErrorConstructor
4+ */
5+
6+ import type { Overwrite } from '@flex-development/tutils'
7+ import type MessageFn from './fn-message'
8+ import type NodeError from './node-error'
9+
10+ /**
11+ * Node.js error constructor type.
12+ *
13+ * @template B - Error constructor type
14+ * @template M - Error message type
15+ * @template T - Error base type
16+ *
17+ * @extends {Overwrite<B, B> }
18+ */
19+ type NodeErrorConstructor <
20+ B extends ErrorConstructor = ErrorConstructor ,
21+ M extends MessageFn | string = string ,
22+ T extends B [ 'prototype' ] = B [ 'prototype' ]
23+ > = Overwrite < B , B > & {
24+ new ( ...args : M extends MessageFn ? Parameters < M > : any [ ] ) : NodeError < T >
25+ ( ...args : M extends MessageFn ? Parameters < M > : any [ ] ) : NodeError < T >
26+ }
27+
28+ export type { NodeErrorConstructor as default }
You can’t perform that action at this time.
0 commit comments