-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Suggestion] --noImplicitUnionWithUndefinded #14070
Comments
This seems like a really odd thing to make an error. There's nothing inherently wrong about making a union with undefined and it's not at all obvious why anyone would need to avoid it on purpose, or why the fact that it's implicit even matters. Maybe some context about what problem led you to this solution would be clarifying. |
I am picking up TS to use with react native. I posted this question on stackoverflow and somebody suggested that I should use an Option type. I really like option types and I have used them in Swift because they are part of the language but I am not suggestion to add them to TS. In my config I have |
I was actually thinking of making it a warning. Related: #6802 |
@masters3d You could specify the return type yourself to make it error when the return is not correct: |
@blakeembrey I could specify the return type which I do often. This is in the same vain as noImplicitAny in my opinion. |
I have another scenario that I believe is related (i.e. implicit union with bottom) though not exactly the same. Given this code:
I expected (and would like) the call to I understand this behavior by default, but
And, I don't believe a type variable should implicitly fall into those assignable types. Also, the sum type is not inferred for non-bottom values. e.g. |
The current rules around when union types are inferred were derived from trying to break only the right amount of code; there aren't any meaningful changes we could make at this point. Without a clearer definition and motivating scenario for OP's flag, there's nothing actionable here. |
TypeScript Version: / nightly (2.2.0-dev.201xxxxx)
Code
Expected behavior:
Being able to tell the compiler to warn on union types which contain Undefined.
This is from the 2.2 dev Whats New Section:
"Note that the union type case only only occurs in --strictNullChecks mode because null and undefined disappear from unions in classic type checking mode."
In the case of the above code, I know why that is retuning
string | undefined
but I want the compiler to complain that I am implicitly setting that function to a union with undefined.Another option is to warn when even I make something implicitly a union.
--noImplicitUnion
I actually don't mind unions just the ones that are undefined even behind the nulls check flag.
Actual behavior:
implicit type of
string | undefined
The text was updated successfully, but these errors were encountered: