File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed
Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,12 @@ type BitSize =
208208 | 31
209209 | 32 ;
210210
211- const PRIMITIVE_SIZES : { [ key in PrimitiveType ] : number } = {
211+ const conforms =
212+ < T > ( ) =>
213+ < U extends T > ( value : U ) : U =>
214+ value ;
215+
216+ const PRIMITIVE_SIZES = conforms < { [ key in PrimitiveType ] : 1 | 2 | 4 | 8 } > ( ) ( {
212217 uint8 : 1 ,
213218 uint16le : 2 ,
214219 uint16be : 2 ,
@@ -227,9 +232,14 @@ const PRIMITIVE_SIZES: { [key in PrimitiveType]: number } = {
227232 floatbe : 4 ,
228233 doublele : 8 ,
229234 doublebe : 8 ,
230- } ;
231-
232- const PRIMITIVE_NAMES : { [ key in PrimitiveType ] : string } = {
235+ } as const ) ;
236+
237+ const PRIMITIVE_NAMES = conforms < {
238+ [ key in PrimitiveType ] :
239+ | `${"Int" | "Uint" } ${8 | 16 | 32 } `
240+ | `Big${"Int" | "Uint" } 64`
241+ | `Float${32 | 64 } `;
242+ } > ( ) ( {
233243 uint8 : "Uint8" ,
234244 uint16le : "Uint16" ,
235245 uint16be : "Uint16" ,
@@ -248,9 +258,11 @@ const PRIMITIVE_NAMES: { [key in PrimitiveType]: string } = {
248258 floatbe : "Float32" ,
249259 doublele : "Float64" ,
250260 doublebe : "Float64" ,
251- } ;
261+ } as const ) ;
252262
253- const PRIMITIVE_LITTLE_ENDIANS : { [ key in PrimitiveType ] : boolean } = {
263+ const PRIMITIVE_LITTLE_ENDIANS = conforms < {
264+ [ key in PrimitiveType ] : boolean ;
265+ } > ( ) ( {
254266 uint8 : false ,
255267 uint16le : true ,
256268 uint16be : false ,
@@ -269,7 +281,7 @@ const PRIMITIVE_LITTLE_ENDIANS: { [key in PrimitiveType]: boolean } = {
269281 floatbe : false ,
270282 doublele : true ,
271283 doublebe : false ,
272- } ;
284+ } as const ) ;
273285
274286type Next < O , N , T > = N extends string
275287 ? Parser <
You can’t perform that action at this time.
0 commit comments