You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceSomeInterface{name?: string;}// these two (correctly) produce compiler errors//var broken1: SomeInterface = { another: 'a' };//var broken2: SomeInterface[] = { another: 'b' };// this does not produce a compiler error but shouldvarbroken3: SomeInterface|SomeInterface[]={another: 'c'};
Expected behavior:
Compilation should fail
Actual behavior:
Compilation succeeds
Note: This behavior only seems to manifest when the interface contains only optional properties. If I change name to be a required property then compilation fails with:
test.ts(10,5): error TS2322: Type '{ [x: number]: undefined; another: string; }' is not assignable to type 'SomeInterface | SomeInterface[]'.
Type '{ [x: number]: undefined; another: string; }' is not assignable to type 'SomeInterface[]'.
Property 'length' is missing in type '{ [x: number]: undefined; another: string; }'.