@@ -72,44 +72,17 @@ export function debugAssert(
72
72
}
73
73
74
74
/**
75
- * Casts `obj1 ` to `S` and `obj2` to ` T`. In non-production builds,
76
- * verifies that `obj1` and `obj2` are instances of `S` and `T` before casting.
75
+ * Casts `obj ` to `T`. In non-production builds, verifies that `obj` is an
76
+ * instance of `T` before casting.
77
77
*/
78
- export function debugCast < S , T > (
79
- obj1 : object ,
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- constructor1 : { new ( ...args : any [ ] ) : S } ,
82
- obj2 : object ,
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- constructor2 : { new ( ...args : any [ ] ) : T }
85
- ) : [ S , T ] | never ;
86
- /**
87
- * Casts `obj` to `S`. In non-production builds, verifies that `obj` is an
88
- * instance of `S` before casting.
89
- */
90
- export function debugCast < S > (
78
+ export function debugCast < T > (
91
79
obj : object ,
92
80
// eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- constructor : { new ( ...args : any [ ] ) : S }
94
- ) : S | never ;
95
- export function debugCast < S , T > (
96
- obj1 : object ,
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- constructor1 : { new ( ...args : any [ ] ) : S } ,
99
- obj2 ?: object ,
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- constructor2 ?: { new ( ...args : any [ ] ) : T }
102
- ) : S | [ S , T ] | never {
103
- debugAssert (
104
- obj1 instanceof constructor1 ,
105
- `Expected type '${ constructor1 . name } ', but was '${ obj1 . constructor . name } '`
106
- ) ;
107
- if ( ! obj2 || ! constructor2 ) {
108
- return obj1 as S ;
109
- }
81
+ constructor : { new ( ...args : any [ ] ) : T }
82
+ ) : T | never {
110
83
debugAssert (
111
- obj2 instanceof constructor2 ,
112
- `Expected type '${ constructor2 . name } ', but was '${ obj2 . constructor . name } '`
84
+ obj instanceof constructor ,
85
+ `Expected type '${ constructor . name } ', but was '${ obj . constructor . name } '`
113
86
) ;
114
- return [ obj1 as S , obj2 as T ] ;
87
+ return obj as T ;
115
88
}
0 commit comments