|
| 1 | +=== tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts === |
| 2 | +// This should behave the same as emptyObjectNotSubtypeOfIndexSignatureContainingObject2.ts |
| 3 | +// Begin types from Lodash. |
| 4 | +interface Dictionary<T> { |
| 5 | +>Dictionary : Symbol(Dictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 0, 0)) |
| 6 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 2, 21)) |
| 7 | + |
| 8 | + [index: string]: T; |
| 9 | +>index : Symbol(index, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 3, 3)) |
| 10 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 2, 21)) |
| 11 | +} |
| 12 | + |
| 13 | +interface NumericDictionary<T> { |
| 14 | +>NumericDictionary : Symbol(NumericDictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 4, 1)) |
| 15 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 6, 28)) |
| 16 | + |
| 17 | + [index: number]: T; |
| 18 | +>index : Symbol(index, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 7, 3)) |
| 19 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 6, 28)) |
| 20 | +} |
| 21 | + |
| 22 | +type ObjectIterator<TObject, TResult> = ( |
| 23 | +>ObjectIterator : Symbol(ObjectIterator, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 8, 1)) |
| 24 | +>TObject : Symbol(TObject, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 20)) |
| 25 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 28)) |
| 26 | + |
| 27 | + value: TObject[keyof TObject], |
| 28 | +>value : Symbol(value, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 41)) |
| 29 | +>TObject : Symbol(TObject, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 20)) |
| 30 | +>TObject : Symbol(TObject, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 20)) |
| 31 | + |
| 32 | + key: string, |
| 33 | +>key : Symbol(key, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 11, 32)) |
| 34 | + |
| 35 | + collection: TObject |
| 36 | +>collection : Symbol(collection, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 12, 14)) |
| 37 | +>TObject : Symbol(TObject, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 20)) |
| 38 | + |
| 39 | +) => TResult; |
| 40 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 10, 28)) |
| 41 | + |
| 42 | +type DictionaryIterator<T, TResult> = ObjectIterator<Dictionary<T>, TResult>; |
| 43 | +>DictionaryIterator : Symbol(DictionaryIterator, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 14, 13)) |
| 44 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 24)) |
| 45 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 26)) |
| 46 | +>ObjectIterator : Symbol(ObjectIterator, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 8, 1)) |
| 47 | +>Dictionary : Symbol(Dictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 0, 0)) |
| 48 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 24)) |
| 49 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 26)) |
| 50 | + |
| 51 | +// In lodash.d.ts this function has many overloads, but this seems to be the problematic one. |
| 52 | +function mapValues<T, TResult>( |
| 53 | +>mapValues : Symbol(mapValues, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 77)) |
| 54 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 19)) |
| 55 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 21)) |
| 56 | + |
| 57 | + obj: Dictionary<T> | NumericDictionary<T> | null | undefined, |
| 58 | +>obj : Symbol(obj, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 31)) |
| 59 | +>Dictionary : Symbol(Dictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 0, 0)) |
| 60 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 19)) |
| 61 | +>NumericDictionary : Symbol(NumericDictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 4, 1)) |
| 62 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 19)) |
| 63 | + |
| 64 | + callback: DictionaryIterator<T, TResult> |
| 65 | +>callback : Symbol(callback, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 20, 63)) |
| 66 | +>DictionaryIterator : Symbol(DictionaryIterator, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 14, 13)) |
| 67 | +>T : Symbol(T, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 19)) |
| 68 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 21)) |
| 69 | + |
| 70 | +): Dictionary<TResult> { |
| 71 | +>Dictionary : Symbol(Dictionary, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 0, 0)) |
| 72 | +>TResult : Symbol(TResult, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 19, 21)) |
| 73 | + |
| 74 | + return null as any; |
| 75 | +} |
| 76 | +// End types from Lodash. |
| 77 | + |
| 78 | +interface Foo { |
| 79 | +>Foo : Symbol(Foo, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 24, 1)) |
| 80 | + |
| 81 | + foo: string; |
| 82 | +>foo : Symbol(Foo.foo, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 27, 15)) |
| 83 | +} |
| 84 | + |
| 85 | +interface Bar { |
| 86 | +>Bar : Symbol(Bar, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 29, 1)) |
| 87 | + |
| 88 | + bar: string; |
| 89 | +>bar : Symbol(Bar.bar, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 31, 15)) |
| 90 | +} |
| 91 | + |
| 92 | +export function fooToBar( |
| 93 | +>fooToBar : Symbol(fooToBar, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 33, 1)) |
| 94 | + |
| 95 | + foos: Record<string, Foo> |
| 96 | +>foos : Symbol(foos, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 35, 25)) |
| 97 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 98 | +>Foo : Symbol(Foo, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 24, 1)) |
| 99 | + |
| 100 | +): Record<string, Bar | null> { |
| 101 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 102 | +>Bar : Symbol(Bar, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 29, 1)) |
| 103 | + |
| 104 | + const result = foos == null ? {} : mapValues(foos, f => f.foo); |
| 105 | +>result : Symbol(result, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 38, 7)) |
| 106 | +>foos : Symbol(foos, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 35, 25)) |
| 107 | +>mapValues : Symbol(mapValues, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 16, 77)) |
| 108 | +>foos : Symbol(foos, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 35, 25)) |
| 109 | +>f : Symbol(f, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 38, 52)) |
| 110 | +>f.foo : Symbol(Foo.foo, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 27, 15)) |
| 111 | +>f : Symbol(f, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 38, 52)) |
| 112 | +>foo : Symbol(Foo.foo, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 27, 15)) |
| 113 | + |
| 114 | + // This line _should_ fail, because `result` is not the right type. |
| 115 | + return result; |
| 116 | +>result : Symbol(result, Decl(emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts, 38, 7)) |
| 117 | +} |
| 118 | + |
0 commit comments