|
| 1 | +mappedTypeTupleConstraintTypeParameterInNameType.ts(45,7): error TS2322: Type 'string | number | bigint' is not assignable to type 'number'. |
| 2 | + Type 'string' is not assignable to type 'number'. |
| 3 | +mappedTypeTupleConstraintTypeParameterInNameType.ts(46,7): error TS2322: Type 'string | number | bigint' is not assignable to type 'string'. |
| 4 | + Type 'number' is not assignable to type 'string'. |
| 5 | +mappedTypeTupleConstraintTypeParameterInNameType.ts(47,7): error TS2322: Type 'string | number | bigint' is not assignable to type 'bigint'. |
| 6 | + Type 'string' is not assignable to type 'bigint'. |
| 7 | + |
| 8 | + |
| 9 | +==== mappedTypeTupleConstraintTypeParameterInNameType.ts (3 errors) ==== |
| 10 | + // based on https://github.com/microsoft/TypeScript/issues/55762 |
| 11 | + |
| 12 | + declare class Decoder<T> { |
| 13 | + decode(arrayBuffer: ArrayBuffer): T; |
| 14 | + } |
| 15 | + |
| 16 | + type ValueTypeOf<T extends Decoder<any>> = T extends Decoder<infer R> |
| 17 | + ? R |
| 18 | + : never; |
| 19 | + |
| 20 | + type StructDescriptor = ReadonlyArray< |
| 21 | + readonly [key: string, type: Decoder<any>] |
| 22 | + >; |
| 23 | + |
| 24 | + type StructTypeFor<Descriptor extends StructDescriptor> = { |
| 25 | + [K in keyof Descriptor as Descriptor[K][0]]: ValueTypeOf<Descriptor[K][1]>; |
| 26 | + }; |
| 27 | + |
| 28 | + class StructDecoder<const Descriptor extends StructDescriptor> extends Decoder< |
| 29 | + StructTypeFor<Descriptor> |
| 30 | + > { |
| 31 | + constructor(descriptor: Descriptor) { |
| 32 | + super(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + declare const i32Decoder: Decoder<number>; |
| 37 | + declare const i64Decoder: Decoder<bigint>; |
| 38 | + |
| 39 | + const structDecoder1 = new StructDecoder([ |
| 40 | + ["a", i32Decoder], |
| 41 | + ["b", i64Decoder], |
| 42 | + ]); |
| 43 | + |
| 44 | + const struct1 = structDecoder1.decode(new ArrayBuffer(100)); |
| 45 | + |
| 46 | + const v1_1: number = struct1.a; |
| 47 | + const v1_2: bigint = struct1.b; |
| 48 | + |
| 49 | + declare const descriptor2: [["a", Decoder<number>], ["b", Decoder<string>], ...["c", Decoder<bigint>][]] |
| 50 | + const structDecoder2 = new StructDecoder(descriptor2); |
| 51 | + |
| 52 | + const struct2 = structDecoder2.decode(new ArrayBuffer(100)); |
| 53 | + |
| 54 | + const v2_1: number = struct2.a; // error, rest element expands to index signature access |
| 55 | + ~~~~ |
| 56 | +!!! error TS2322: Type 'string | number | bigint' is not assignable to type 'number'. |
| 57 | +!!! error TS2322: Type 'string' is not assignable to type 'number'. |
| 58 | + const v2_2: string = struct2.b; // error, rest element expands to index signature access |
| 59 | + ~~~~ |
| 60 | +!!! error TS2322: Type 'string | number | bigint' is not assignable to type 'string'. |
| 61 | +!!! error TS2322: Type 'number' is not assignable to type 'string'. |
| 62 | + const v2_3: bigint = struct2.c; // error, rest element expands to index signature access |
| 63 | + ~~~~ |
| 64 | +!!! error TS2322: Type 'string | number | bigint' is not assignable to type 'bigint'. |
| 65 | +!!! error TS2322: Type 'string' is not assignable to type 'bigint'. |
| 66 | + |
0 commit comments