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
classAllOptionalClass{optional?: string;}letx=newAllOptionalClass();x='asdf';// goodclassRequiredClass{requiredClass: string;}lety=newRequiredClass();y='asdf';// Type '"asdf"' is not assignable to type 'RequiredClass'interfaceIAllOptional{optional?: string;}leta : IAllOptional={optional: 'asdf'};a='asdf';// goodinterfaceIRequired{required: string;}letb : IRequired={required: 'asdf'};b='asdf';// Type '"asdf"' is not assignable to type 'IRequired'
Expected behavior:
I would expect x = 'asdf'; to fail with the same error as y = 'asdf';, and I would expeect a = 'asdf'; to fail with the same error as b = 'asdf';
Actual behavior:
A variable that has a type of a class or interface with all optional properties can have anything assigned to it as far as I can tell.
The text was updated successfully, but these errors were encountered:
It may be worth noting that the way I came across this was actually in a class that implements an interface with only optional properties.
interfaceIAllOptional{optional?: string;}interfaceRecordClass{optional? : IAllOptional;}classAllOptionalimplementsRecordClass{optional: number;// would expect this to be an error}
TypeScript Version: 2.1.4
Code
Expected behavior:
I would expect
x = 'asdf';
to fail with the same error asy = 'asdf';
, and I would expeecta = 'asdf';
to fail with the same error asb = 'asdf';
Actual behavior:
A variable that has a type of a class or interface with all optional properties can have anything assigned to it as far as I can tell.
The text was updated successfully, but these errors were encountered: