2014-07-13 01:04:16 +02:00
|
|
|
==== tests/cases/compiler/optionalPropertiesTest.ts (4 errors) ====
|
|
|
|
var x: {p1:number; p2?:string; p3?:{():number;};};
|
|
|
|
|
|
|
|
interface IFoo
|
|
|
|
{
|
|
|
|
id: number;
|
|
|
|
name?: string;
|
|
|
|
print?(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var foo: IFoo;
|
|
|
|
foo = { id: 1234 }; // Ok
|
|
|
|
foo = { id: 1234, name: "test" }; // Ok
|
|
|
|
foo = { name: "test" }; // Error, id missing
|
|
|
|
~~~
|
|
|
|
!!! Type '{ name: string; }' is not assignable to type 'IFoo':
|
|
|
|
!!! Property 'id' is missing in type '{ name: string; }'.
|
|
|
|
foo = {id: 1234, print:()=>{}} // Ok
|
|
|
|
|
|
|
|
var s = foo.name || "default";
|
|
|
|
if (foo.print !== undefined) foo.print();
|
|
|
|
|
|
|
|
interface i1 { M: () => void; };
|
|
|
|
interface i2 { M?: () => void; };
|
|
|
|
interface i3 { M: number; };
|
|
|
|
interface i4 { M?: number; };
|
|
|
|
|
|
|
|
var test1: i1 = {};
|
2014-07-19 02:30:06 +02:00
|
|
|
~~~~~
|
2014-07-13 01:04:16 +02:00
|
|
|
!!! Type '{}' is not assignable to type 'i1':
|
|
|
|
!!! Property 'M' is missing in type '{}'.
|
|
|
|
var test2: i3 = {};
|
2014-07-19 02:30:06 +02:00
|
|
|
~~~~~
|
2014-07-13 01:04:16 +02:00
|
|
|
!!! Type '{}' is not assignable to type 'i3':
|
|
|
|
!!! Property 'M' is missing in type '{}'.
|
|
|
|
var test3: i2 = {};
|
|
|
|
var test4: i4 = {};
|
|
|
|
var test5: i1 = { M: function () { } };
|
|
|
|
var test6: i3 = { M: 5 };
|
|
|
|
var test7: i2 = { M: function () { } };
|
|
|
|
test7 = {};
|
|
|
|
var test8: i4 = { M: 5 }
|
|
|
|
test8 = {};
|
|
|
|
var test9_1: i2;
|
|
|
|
var test9_2: i1;
|
|
|
|
test9_1 = test9_2;
|
|
|
|
var test10_1: i1;
|
|
|
|
var test10_2: i2;
|
|
|
|
test10_1 = test10_2;
|
|
|
|
~~~~~~~~
|
|
|
|
!!! Type 'i2' is not assignable to type 'i1':
|
2014-09-17 19:36:32 +02:00
|
|
|
!!! Property 'M' is optional in type 'i2' but required in type 'i1'.
|