1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
=== tests/cases/compiler/contextualTypingOfObjectLiterals.ts ===
var obj1: { [x: string]: string; };
>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3))
>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 0, 13))
var obj2 = {x: ""};
>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3))
>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 1, 12))
obj1 = {}; // Ok
>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3))
obj1 = obj2; // Error - indexer doesn't match
>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3))
>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3))
function f(x: { [s: string]: string }) { }
>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12))
>x : Symbol(x, Decl(contextualTypingOfObjectLiterals.ts, 5, 11))
>s : Symbol(s, Decl(contextualTypingOfObjectLiterals.ts, 5, 17))
f({}); // Ok
>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12))
f(obj1); // Ok
>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12))
>obj1 : Symbol(obj1, Decl(contextualTypingOfObjectLiterals.ts, 0, 3))
f(obj2); // Error - indexer doesn't match
>f : Symbol(f, Decl(contextualTypingOfObjectLiterals.ts, 3, 12))
>obj2 : Symbol(obj2, Decl(contextualTypingOfObjectLiterals.ts, 1, 3))
|