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
Unfortunately, this isn't a bug: you are returning valid values for TypeOptions here. Because ISomeOtherType and IStillSomeOtherType have only optional parameters, the empty object {} is a valid value for those interfaces. And since any extension of those interfaces is also valid as a value for those interfaces, that means any extension of {} is valid here. Which is to say, literally anything at all.
TypeScript does not have any way of specifying that you want objects that only have the indicated properties. You are always allowed to use bigger objects.
You might consider giving those interface some unique string literal identifier property. On our project, we call this property kind. So for example you could have:
I understand, I thought it was possible to check that at least an empty object was being returned. But I'll use your recommendation with the kind pattern.
Thanks
TypeScript Version: 2.2.1
Code
Expected behavior:
TypeScript should check that the returned value is of the three types defined in the type alias TypeOptions
Actual behavior:
Values of a type different from the specified can be returned, such as strings and numbers.
Link to playground
The text was updated successfully, but these errors were encountered: