-
Notifications
You must be signed in to change notification settings - Fork 12.8k
(nullable?.methodOrProperty ?? defaultValue) === defaultValue
should be a type guard
#58196
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
Comments
Duplicate of #54825. |
I doubt this is a duplicate. The linked issue is all about whether TS should know that Also the linked issue mentions another issue ( #48536 (comment) ) but that's a different topic too. This issue does not include any request to reason about βorβ logics. |
The underlying issue is the same. |
@MartinJohns You have said that that issue is difficult to be fixed for a "design limitation", but this is a more limited form and easier to be fixed. This issue must not be closed just because of the combination of the "duplication" and that "design limitation". |
I have added an additional limitation that the fallback value is the same as the value of the other operand of the equality or non-or-equal comparison ( |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Why no advanced notice? |
Ryan considers it a duplicate, that's why he marked the issue as such. He surely read your comment, but it doesn't change anything. The underlaying issue is still the same. Type narrowing is done on variables, not expressions. By adding the
It's been marked as Duplicate for 4 days. That's the advance notice. |
@MartinJohns Do you mean #48536 (comment) ?
FYI C# 8.0+'s null flow analysis can recognize this pattern. You will be able to get its specification from https://ecma-international.org/publications-and-standards/standards/ecma-334/ next year. This patern might as well be considered to be added to the backlog. TS may not be able to handle the type
FYI, https://github.com/actions/stale, which has been famous, politely writes a post before closing, but your bot does not. However I do not require the bot to be improved because this improvement is just a bullshit job for your team and even hell can be home. |
Please note that I am not a member of the TypeScript team. It's not my bot. Besides that, the bot did write a polite comment before closing the issue. |
Oh no, you are not Owner or Member. I have misunderstood and just noticed it. Sorry. |
π Search Terms
??
)π Version & Regression Information
4.9 & Playground
β― Playground Link
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMOcAUAjAhgJwFyIDOUOMYA5gNoC6iAPomCADbP2LgAmApsGd5wCUiAN4AoRJMQ5uUEDiSZcAfgB0zbhSgALRMuWIADMICEAXjNHEAMmuIAslh3q45JTnWbyOwQG4xAL5AA
π» Code
π Actual behavior
'bar' is possibly 'null' or 'undefined'.
π Expected behavior
No errors
Additional information about the issue
Math.log(bar.length)
can be a React component in real applications.I have to write the following instead as of now:
The text was updated successfully, but these errors were encountered: