2014-07-13 01:04:16 +02:00
|
|
|
//// [contextualTypingOfObjectLiterals.ts]
|
|
|
|
var obj1: { [x: string]: string; };
|
|
|
|
var obj2 = {x: ""};
|
|
|
|
obj1 = {}; // Ok
|
|
|
|
obj1 = obj2; // Error - indexer doesn't match
|
|
|
|
|
|
|
|
function f(x: { [s: string]: string }) { }
|
|
|
|
|
|
|
|
f({}); // Ok
|
|
|
|
f(obj1); // Ok
|
|
|
|
f(obj2); // Error - indexer doesn't match
|
|
|
|
|
|
|
|
//// [contextualTypingOfObjectLiterals.js]
|
|
|
|
var obj1;
|
|
|
|
var obj2 = { x: "" };
|
2014-08-16 00:49:09 +02:00
|
|
|
obj1 = {}; // Ok
|
|
|
|
obj1 = obj2; // Error - indexer doesn't match
|
2015-02-07 03:45:09 +01:00
|
|
|
function f(x) { }
|
2014-08-16 00:49:09 +02:00
|
|
|
f({}); // Ok
|
|
|
|
f(obj1); // Ok
|
|
|
|
f(obj2); // Error - indexer doesn't match
|