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; }'.
The text was updated successfully, but these errors were encountered:
We currently do the excess property check only if no constituent of the target has an index signature (of either kind). An array has only a numeric index signature and we probably should factor that into our reasoning. Specifically, we should say that if some constituent of the target has a numeric index signature, then only numerically named properties are expected.
TypeScript Version:
1.8.10
Code
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:The text was updated successfully, but these errors were encountered: