-
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
Use of implicit union return type causes "'boolean' is not assignable to type 'false'" #19212
Comments
Duplicate of #1373 |
Thanks for the detailed reply. I still find it odd (counter-intuitive) that TypeScript playground using boolean TypeScript playground using false Does this narrow the scope of a potential fix? As it stands we're seeing the unwanted compilation error when using @graphql. |
As the linked issue mentions, we don't currently use information about the base class to inform the type of a derived class method. So understand the below in that context (i.e. we think the best fix involves using that information) There are rules around widening that attempt to figure out what behavior you're trying expose in a method. If you wrote something like someMethod() {
if (...) return 3; else return 6;
} we think that you want the signature We do infer All these rules came from experimental data produced when we added literal types to the type system (in other words, we messed with them until we got the "best" set of breaking changes) and are based on our "best guess" about what the inferred return type should be. We already tweaked these rules to the best of our ability and any change here would move away from the local maximum. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.6.0-dev.20171015
This relates to the render method of React components, specifically the use of
false
in the union return type:I've create a stand-alone example that demonstrates the issue. See the code comments for instructions.
Code
Expected behavior:
For TestImplicitReturn I should not be required to manually add
: false
as return type.For TestControlFlow I should not be required to also return a Date to satisfy the type checker.
Actual behavior:
For TestImplicitReturn the compiler outputs:
For TestImplicitReturnType the compiler outputs the following when the date return statement is removed:
The text was updated successfully, but these errors were encountered: