1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
=== tests/cases/compiler/optionalPropertiesTest.ts ===
var x: {p1:number; p2?:string; p3?:{():number;};};
>x : { p1: number; p2?: string; p3?: () => number; }
>p1 : number
>p2 : string
>p3 : () => number
interface IFoo
{
id: number;
>id : number
name?: string;
>name : string
print?(): void;
>print : () => void
}
var foo: IFoo;
>foo : IFoo
foo = { id: 1234 }; // Ok
>foo = { id: 1234 } : { id: number; }
>foo : IFoo
>{ id: 1234 } : { id: number; }
>id : number
>1234 : 1234
foo = { id: 1234, name: "test" }; // Ok
>foo = { id: 1234, name: "test" } : { id: number; name: string; }
>foo : IFoo
>{ id: 1234, name: "test" } : { id: number; name: string; }
>id : number
>1234 : 1234
>name : string
>"test" : "test"
foo = { name: "test" }; // Error, id missing
>foo = { name: "test" } : { name: string; }
>foo : IFoo
>{ name: "test" } : { name: string; }
>name : string
>"test" : "test"
foo = {id: 1234, print:()=>{}} // Ok
>foo = {id: 1234, print:()=>{}} : { id: number; print: () => void; }
>foo : IFoo
>{id: 1234, print:()=>{}} : { id: number; print: () => void; }
>id : number
>1234 : 1234
>print : () => void
>()=>{} : () => void
var s = foo.name || "default";
>s : string
>foo.name || "default" : string
>foo.name : string
>foo : IFoo
>name : string
>"default" : "default"
if (foo.print !== undefined) foo.print();
>foo.print !== undefined : boolean
>foo.print : () => void
>foo : IFoo
>print : () => void
>undefined : undefined
>foo.print() : void
>foo.print : () => void
>foo : IFoo
>print : () => void
interface i1 { M: () => void; };
>M : () => void
interface i2 { M?: () => void; };
>M : () => void
interface i3 { M: number; };
>M : number
interface i4 { M?: number; };
>M : number
var test1: i1 = {};
>test1 : i1
>{} : {}
var test2: i3 = {};
>test2 : i3
>{} : {}
var test3: i2 = {};
>test3 : i2
>{} : {}
var test4: i4 = {};
>test4 : i4
>{} : {}
var test5: i1 = { M: function () { } };
>test5 : i1
>{ M: function () { } } : { M: () => void; }
>M : () => void
>function () { } : () => void
var test6: i3 = { M: 5 };
>test6 : i3
>{ M: 5 } : { M: number; }
>M : number
>5 : 5
var test7: i2 = { M: function () { } };
>test7 : i2
>{ M: function () { } } : { M: () => void; }
>M : () => void
>function () { } : () => void
test7 = {};
>test7 = {} : {}
>test7 : i2
>{} : {}
var test8: i4 = { M: 5 }
>test8 : i4
>{ M: 5 } : { M: number; }
>M : number
>5 : 5
test8 = {};
>test8 = {} : {}
>test8 : i4
>{} : {}
var test9_1: i2;
>test9_1 : i2
var test9_2: i1;
>test9_2 : i1
test9_1 = test9_2;
>test9_1 = test9_2 : i1
>test9_1 : i2
>test9_2 : i1
var test10_1: i1;
>test10_1 : i1
var test10_2: i2;
>test10_2 : i2
test10_1 = test10_2;
>test10_1 = test10_2 : i2
>test10_1 : i1
>test10_2 : i2
|