|
| 1 | +=== tests/cases/compiler/mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts === |
| 2 | +// repro from https://github.com/microsoft/TypeScript/issues/54000 |
| 3 | + |
| 4 | +function foo<T>(record: Record<string, T>, entity: T) {} |
| 5 | +>foo : Symbol(foo, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 0, 0)) |
| 6 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 13)) |
| 7 | +>record : Symbol(record, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 16)) |
| 8 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 9 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 13)) |
| 10 | +>entity : Symbol(entity, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 42)) |
| 11 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 13)) |
| 12 | + |
| 13 | +type StringArrayRecord = Record<string, string[]>; |
| 14 | +>StringArrayRecord : Symbol(StringArrayRecord, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 56)) |
| 15 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 16 | + |
| 17 | +function test() { |
| 18 | +>test : Symbol(test, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 4, 50)) |
| 19 | + |
| 20 | + const working: Record<string, string[]> = {}; |
| 21 | +>working : Symbol(working, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 7, 7)) |
| 22 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 23 | + |
| 24 | + foo(working, []); |
| 25 | +>foo : Symbol(foo, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 0, 0)) |
| 26 | +>working : Symbol(working, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 7, 7)) |
| 27 | + |
| 28 | + const working2: StringArrayRecord = {}; |
| 29 | +>working2 : Symbol(working2, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 10, 7)) |
| 30 | +>StringArrayRecord : Symbol(StringArrayRecord, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 2, 56)) |
| 31 | + |
| 32 | + foo(working2, []); |
| 33 | +>foo : Symbol(foo, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 0, 0)) |
| 34 | +>working2 : Symbol(working2, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 10, 7)) |
| 35 | +} |
| 36 | + |
| 37 | +// showcase the same behavior with index signature |
| 38 | + |
| 39 | +function bar<T>(record: { [k: string]: T }, entity: T) {} |
| 40 | +>bar : Symbol(bar, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 12, 1)) |
| 41 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 13)) |
| 42 | +>record : Symbol(record, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 16)) |
| 43 | +>k : Symbol(k, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 27)) |
| 44 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 13)) |
| 45 | +>entity : Symbol(entity, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 43)) |
| 46 | +>T : Symbol(T, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 13)) |
| 47 | + |
| 48 | +type StringArrayIndexSignature = { [k: string]: string[] }; |
| 49 | +>StringArrayIndexSignature : Symbol(StringArrayIndexSignature, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 57)) |
| 50 | +>k : Symbol(k, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 18, 36)) |
| 51 | + |
| 52 | +function test2() { |
| 53 | +>test2 : Symbol(test2, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 18, 59)) |
| 54 | + |
| 55 | + const working: { [k: string]: string[] } = {}; |
| 56 | +>working : Symbol(working, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 21, 7)) |
| 57 | +>k : Symbol(k, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 21, 20)) |
| 58 | + |
| 59 | + bar(working, []); |
| 60 | +>bar : Symbol(bar, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 12, 1)) |
| 61 | +>working : Symbol(working, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 21, 7)) |
| 62 | + |
| 63 | + const working2: StringArrayIndexSignature = {}; |
| 64 | +>working2 : Symbol(working2, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 24, 7)) |
| 65 | +>StringArrayIndexSignature : Symbol(StringArrayIndexSignature, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 16, 57)) |
| 66 | + |
| 67 | + bar(working2, []); |
| 68 | +>bar : Symbol(bar, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 12, 1)) |
| 69 | +>working2 : Symbol(working2, Decl(mappedTypeWithPrimitiveTypeParameterConstraintInferencePriority.ts, 24, 7)) |
| 70 | +} |
| 71 | + |
0 commit comments