File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,6 @@ export { useConnection } from './composables/useConnection'
73
73
export { useHandleConnections } from './composables/useHandleConnections'
74
74
export { useNodesData } from './composables/useNodesData'
75
75
76
- export { VueFlowError , ErrorCode } from './utils/errors'
76
+ export { VueFlowError , ErrorCode , isErrorOfType } from './utils/errors'
77
77
78
78
export * from './types'
Original file line number Diff line number Diff line change @@ -35,15 +35,23 @@ const messages = {
35
35
[ ErrorCode . EDGE_NOT_FOUND ] : ( id : string ) => `Edge not found\nEdge: ${ id } ` ,
36
36
} as const
37
37
38
- export class VueFlowError < T extends ErrorCode = ErrorCode > extends Error {
38
+ type ErrorArgs < T extends ErrorCode > = ( typeof messages ) [ T ] extends ( ...args : any [ ] ) => string
39
+ ? Parameters < ( typeof messages ) [ T ] >
40
+ : never
41
+
42
+ export class VueFlowError < T extends ErrorCode = ErrorCode , Args extends ErrorArgs < T > = ErrorArgs < T > > extends Error {
43
+ name = 'VueFlowError'
39
44
code : T
40
- constructor (
41
- code : T ,
42
- ...args : ( typeof messages ) [ T ] extends ( ...args : any [ ] ) => string ? Parameters < ( typeof messages ) [ T ] > : never
43
- ) {
45
+ args : Args
46
+
47
+ constructor ( code : T , ...args : Args ) {
44
48
// @ts -expect-error - TS doesn't know that the message is a key of messages
45
49
super ( messages [ code ] ?.( ...args ) )
46
-
47
50
this . code = code
51
+ this . args = args
48
52
}
49
53
}
54
+
55
+ export function isErrorOfType < T extends ErrorCode > ( error : VueFlowError , code : T ) : error is VueFlowError < T > {
56
+ return error . code === code
57
+ }
You can’t perform that action at this time.
0 commit comments