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
Expected behavior: The type of Example#ex is inferred to 1 | 2 and the example compiles.
Actual behavior: The type of Example#ex is inferred to number, which is not a subtype of 1 | 2, so the example does not compile.
Suggested solution?: If a property of a class has its type inferred from a default value, and that type isn't compatible with all interfaces the class explicitly implements, try inferring the intersection of the types required by the interfaces. So:
interfaceOneOrTwo{ex: 1|2;}interfaceTwoOrThree{ex: 2|3;}classExampleimplementsOneOrTwo,TwoOrThree{ex=2;// should be inferred as type (1 | 2) & (2 | 3), i.e. 2}
For simplicity, if that type doesn't work, the original type (number here) should be used in error messages. Maybe the message should be changed, even.
The text was updated successfully, but these errors were encountered:
Bug? Suggestion? Oh well.
TypeScript Version: 2.7.0-dev.20171024
Code
Expected behavior: The type of
Example#ex
is inferred to1 | 2
and the example compiles.Actual behavior: The type of
Example#ex
is inferred tonumber
, which is not a subtype of1 | 2
, so the example does not compile.Suggested solution?: If a property of a class has its type inferred from a default value, and that type isn't compatible with all interfaces the class explicitly implements, try inferring the intersection of the types required by the interfaces. So:
For simplicity, if that type doesn't work, the original type (
number
here) should be used in error messages. Maybe the message should be changed, even.The text was updated successfully, but these errors were encountered: