2014-11-05 21:26:03 +01:00
|
|
|
tests/cases/compiler/optionalPropertiesTest.ts(14,1): error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'.
|
2014-09-12 22:35:07 +02:00
|
|
|
Property 'id' is missing in type '{ name: string; }'.
|
2014-11-05 21:26:03 +01:00
|
|
|
tests/cases/compiler/optionalPropertiesTest.ts(25,5): error TS2322: Type '{}' is not assignable to type 'i1'.
|
2014-09-12 22:35:07 +02:00
|
|
|
Property 'M' is missing in type '{}'.
|
2014-11-05 21:26:03 +01:00
|
|
|
tests/cases/compiler/optionalPropertiesTest.ts(26,5): error TS2322: Type '{}' is not assignable to type 'i3'.
|
2014-09-12 22:35:07 +02:00
|
|
|
Property 'M' is missing in type '{}'.
|
2014-11-05 21:26:03 +01:00
|
|
|
tests/cases/compiler/optionalPropertiesTest.ts(40,1): error TS2322: Type 'i2' is not assignable to type 'i1'.
|
2014-09-18 02:05:45 +02:00
|
|
|
Property 'M' is optional in type 'i2' but required in type 'i1'.
|
2014-09-12 22:35:07 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
~~~
|
2014-11-05 21:26:03 +01:00
|
|
|
!!! error TS2322: Type '{ name: string; }' is not assignable to type 'IFoo'.
|
|
|
|
!!! error TS2322: Property 'id' is missing in type '{ name: string; }'.
|
2014-07-13 01:04:16 +02:00
|
|
|
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-11-05 21:26:03 +01:00
|
|
|
!!! error TS2322: Type '{}' is not assignable to type 'i1'.
|
|
|
|
!!! error TS2322: Property 'M' is missing in type '{}'.
|
2014-07-13 01:04:16 +02:00
|
|
|
var test2: i3 = {};
|
2014-07-19 02:30:06 +02:00
|
|
|
~~~~~
|
2014-11-05 21:26:03 +01:00
|
|
|
!!! error TS2322: Type '{}' is not assignable to type 'i3'.
|
|
|
|
!!! error TS2322: Property 'M' is missing in type '{}'.
|
2014-07-13 01:04:16 +02:00
|
|
|
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;
|
|
|
|
~~~~~~~~
|
2014-11-05 21:26:03 +01:00
|
|
|
!!! error TS2322: Type 'i2' is not assignable to type 'i1'.
|
|
|
|
!!! error TS2322: Property 'M' is optional in type 'i2' but required in type 'i1'.
|