2014-07-13 01:04:16 +02:00
|
|
|
//// [typesWithOptionalProperty.ts]
|
|
|
|
// basic uses of optional properties without errors
|
|
|
|
|
|
|
|
interface I {
|
|
|
|
foo: string;
|
|
|
|
bar?: number;
|
|
|
|
baz? (): string;
|
|
|
|
}
|
|
|
|
|
|
|
|
var a: {
|
|
|
|
foo: string;
|
|
|
|
bar?: number;
|
|
|
|
baz? (): string;
|
|
|
|
};
|
|
|
|
|
|
|
|
var b = { foo: '' };
|
|
|
|
var c = { foo: '', bar: 3 };
|
|
|
|
var d = { foo: '', bar: 3, baz: () => '' };
|
|
|
|
|
|
|
|
var i: I;
|
|
|
|
|
|
|
|
i = b;
|
|
|
|
i = c;
|
|
|
|
i = d;
|
|
|
|
|
|
|
|
a = b;
|
|
|
|
a = c;
|
|
|
|
a = d;
|
|
|
|
|
|
|
|
i = a;
|
|
|
|
a = i;
|
|
|
|
|
|
|
|
//// [typesWithOptionalProperty.js]
|
2014-08-19 19:43:13 +02:00
|
|
|
// basic uses of optional properties without errors
|
2014-07-13 01:04:16 +02:00
|
|
|
var a;
|
|
|
|
var b = { foo: '' };
|
|
|
|
var c = { foo: '', bar: 3 };
|
|
|
|
var d = { foo: '', bar: 3, baz: function () { return ''; } };
|
|
|
|
var i;
|
|
|
|
i = b;
|
|
|
|
i = c;
|
|
|
|
i = d;
|
|
|
|
a = b;
|
|
|
|
a = c;
|
|
|
|
a = d;
|
|
|
|
i = a;
|
|
|
|
a = i;
|