File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Memory } from "./memory" ;
2
- import { pointer } from "./types" ;
2
+ import { assertNever , pointer } from "./types" ;
3
3
4
4
export const enum Kind {
5
5
Boolean = 0 ,
@@ -44,7 +44,7 @@ export const decode = (
44
44
return undefined ;
45
45
46
46
default :
47
- throw new Error ( `JSValue Type kind "${ kind } " is not supported` ) ;
47
+ assertNever ( kind , `JSValue Type kind "${ kind } " is not supported` ) ;
48
48
}
49
49
} ;
50
50
@@ -81,7 +81,8 @@ export const write = (
81
81
memory . writeUint32 ( payload1_ptr , memory . retain ( value ) ) ;
82
82
} ;
83
83
84
- switch ( typeof value ) {
84
+ const type = typeof value ;
85
+ switch ( type ) {
85
86
case "boolean" : {
86
87
memory . writeUint32 ( kind_ptr , exceptionBit | Kind . Boolean ) ;
87
88
memory . writeUint32 ( payload1_ptr , value ? 1 : 0 ) ;
@@ -117,6 +118,6 @@ export const write = (
117
118
break ;
118
119
}
119
120
default :
120
- throw new Error ( `Type "${ typeof value } " is not supported yet` ) ;
121
+ assertNever ( type , `Type "${ type } " is not supported yet` ) ;
121
122
}
122
123
} ;
Original file line number Diff line number Diff line change @@ -124,3 +124,7 @@ export type TypedArray =
124
124
// | BigUint64ArrayConstructor
125
125
| Float32ArrayConstructor
126
126
| Float64ArrayConstructor ;
127
+
128
+ export function assertNever ( x : never , message : string ) {
129
+ throw new Error ( message ) ;
130
+ }
You can’t perform that action at this time.
0 commit comments