-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interface Inferred from Property Not Rejecting Invalid Properties #50732
Comments
Duplicate of #20863. Your object is a valid You should instead create a discriminated union type. |
IIRC this is a limitation of excess property checking; if the property exists in any of the union constituents, it isn't flagged. Note that excess property errors are not type errors per se; TypeScript doesn't support exact types. |
Thank you for the swift responses. I am happy with the explanation and can work around my issue. |
Bug Report
π Search Terms
"type infer", "conditional interface"
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The
test
object with atype
value of2
should flag thestring
property as invalid, since it is not inIBase
orIDate
, but the object is considered valid.π Expected behavior
The
test
object should infer its interface from the value oftype
. Any valid value could be anIBase
, but a value of2
should not be anIDate
and a value of3
should not be anIString
.The text was updated successfully, but these errors were encountered: