mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
35 lines
1.4 KiB
Plaintext
35 lines
1.4 KiB
Plaintext
//// [tests/cases/compiler/contextualTypingOfObjectLiterals.ts] ////
|
|
|
|
=== 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))
|
|
|