|
| 1 | +=== tests/cases/compiler/inferenceOptionalPropertiesToIndexSignatures.ts === |
| 2 | +declare function foo<T>(obj: { [x: string]: T }): T; |
| 3 | +>foo : Symbol(foo, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 0)) |
| 4 | +>T : Symbol(T, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 21)) |
| 5 | +>obj : Symbol(obj, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 24)) |
| 6 | +>x : Symbol(x, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 32)) |
| 7 | +>T : Symbol(T, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 21)) |
| 8 | +>T : Symbol(T, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 21)) |
| 9 | + |
| 10 | +declare const x1: { a: string, b: number }; |
| 11 | +>x1 : Symbol(x1, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 2, 13)) |
| 12 | +>a : Symbol(a, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 2, 19)) |
| 13 | +>b : Symbol(b, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 2, 30)) |
| 14 | + |
| 15 | +declare const x2: { a: string, b: number | undefined }; |
| 16 | +>x2 : Symbol(x2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 3, 13)) |
| 17 | +>a : Symbol(a, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 3, 19)) |
| 18 | +>b : Symbol(b, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 3, 30)) |
| 19 | + |
| 20 | +declare const x3: { a: string, b?: number }; |
| 21 | +>x3 : Symbol(x3, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 4, 13)) |
| 22 | +>a : Symbol(a, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 4, 19)) |
| 23 | +>b : Symbol(b, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 4, 30)) |
| 24 | + |
| 25 | +declare const x4: { a: string, b?: number | undefined }; |
| 26 | +>x4 : Symbol(x4, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 5, 13)) |
| 27 | +>a : Symbol(a, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 5, 19)) |
| 28 | +>b : Symbol(b, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 5, 30)) |
| 29 | + |
| 30 | +let a1 = foo(x1); // string | number |
| 31 | +>a1 : Symbol(a1, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 7, 3)) |
| 32 | +>foo : Symbol(foo, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 0)) |
| 33 | +>x1 : Symbol(x1, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 2, 13)) |
| 34 | + |
| 35 | +let a2 = foo(x2); // string | number | undefined |
| 36 | +>a2 : Symbol(a2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 8, 3)) |
| 37 | +>foo : Symbol(foo, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 0)) |
| 38 | +>x2 : Symbol(x2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 3, 13)) |
| 39 | + |
| 40 | +let a3 = foo(x3); // string | number |
| 41 | +>a3 : Symbol(a3, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 9, 3)) |
| 42 | +>foo : Symbol(foo, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 0)) |
| 43 | +>x3 : Symbol(x3, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 4, 13)) |
| 44 | + |
| 45 | +let a4 = foo(x4); // string | number |
| 46 | +>a4 : Symbol(a4, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 10, 3)) |
| 47 | +>foo : Symbol(foo, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 0, 0)) |
| 48 | +>x4 : Symbol(x4, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 5, 13)) |
| 49 | + |
| 50 | +// Repro from #43045 |
| 51 | + |
| 52 | +const param2 = Math.random() < 0.5 ? 'value2' : null; |
| 53 | +>param2 : Symbol(param2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 14, 5)) |
| 54 | +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 55 | +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) |
| 56 | +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 57 | + |
| 58 | +const obj = { |
| 59 | +>obj : Symbol(obj, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 16, 5)) |
| 60 | + |
| 61 | + param1: 'value1', |
| 62 | +>param1 : Symbol(param1, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 16, 13)) |
| 63 | + |
| 64 | + ...(param2 ? {param2} : {}) |
| 65 | +>param2 : Symbol(param2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 14, 5)) |
| 66 | +>param2 : Symbol(param2, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 18, 18)) |
| 67 | + |
| 68 | +}; |
| 69 | + |
| 70 | +const query = Object.entries(obj).map( |
| 71 | +>query : Symbol(query, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 21, 5)) |
| 72 | +>Object.entries(obj).map( ([k, v]) => `${k}=${encodeURIComponent(v)}`).join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) |
| 73 | +>Object.entries(obj).map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) |
| 74 | +>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) |
| 75 | +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 76 | +>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) |
| 77 | +>obj : Symbol(obj, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 16, 5)) |
| 78 | +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) |
| 79 | + |
| 80 | + ([k, v]) => `${k}=${encodeURIComponent(v)}` |
| 81 | +>k : Symbol(k, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 22, 6)) |
| 82 | +>v : Symbol(v, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 22, 8)) |
| 83 | +>k : Symbol(k, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 22, 6)) |
| 84 | +>encodeURIComponent : Symbol(encodeURIComponent, Decl(lib.es5.d.ts, --, --)) |
| 85 | +>v : Symbol(v, Decl(inferenceOptionalPropertiesToIndexSignatures.ts, 22, 8)) |
| 86 | + |
| 87 | +).join('&'); |
| 88 | +>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) |
| 89 | + |
0 commit comments