We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
optional chaining type narrowing
https://www.typescriptlang.org/play/?#code/C4TwDgpgBA8mwEsD2A7KBeKBvKpIC4oAiAZSQFsIiAaKANwEMAbAVwkJRfICMIAnKAF8oAH2y5w7YgDlUVIQG4AUEoAmEAMZMGfaADMWKDYlRQAzhQhwTKABQBKQteQplSg0ZtQA7gmAALJBZgAFUUdT0EFAhVBw4uXgExQwiomOwlKCgmCGAoJHgXJ0LUNyyAenKfJD4AazNMqAQ9KFtbAq9MC0pnVAd7ADo8aHRRqAByMkpx+wysrN1gFj40DpcBxlYIZSzBFQXc5bQUiEjo1WU9tU1tXSgPYxdzS16UZle42BK0ZPDTtIuKgeXjAfCQ3By5AYiA0n04PH4oigJzO6SwjRyeTWqGKXl+qXOZSglSgKCQeW8NXqjWarXa3wwzx633e336AH4hpIMGNJpYZnN5osjvlvhtmGwdkJ9sSqpS6g0sti0F0XiymB97FLafSbJzhjzMHzprN0fMoMKVqKbOKtlKrgcllaUQDLkogA
type Option = { type: "Some", value: number } | { type: "None" }; declare function someOption(): Option; function withoutUndefined(): number | undefined { let option: Option; // works if ((option = someOption()).type === 'Some') { return option.value; } return undefined; } declare function someOptionalOption(): Option | undefined; function problematic(): number | undefined { let option: Option | undefined; // not works if ((option = someOptionalOption())?.type === 'Some') { return option.value; } // works option = someOptionalOption(); if (option?.type === 'Some') { return option.value; } return undefined; }
Error 'option' is possibly 'undefined'. occurs
'option' is possibly 'undefined'.
No error
No response
The text was updated successfully, but these errors were encountered:
Duplicate of #56998
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
π Search Terms
optional chaining type narrowing
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBA8mwEsD2A7KBeKBvKpIC4oAiAZSQFsIiAaKANwEMAbAVwkJRfICMIAnKAF8oAH2y5w7YgDlUVIQG4AUEoAmEAMZMGfaADMWKDYlRQAzhQhwTKABQBKQteQplSg0ZtQA7gmAALJBZgAFUUdT0EFAhVBw4uXgExQwiomOwlKCgmCGAoJHgXJ0LUNyyAenKfJD4AazNMqAQ9KFtbAq9MC0pnVAd7ADo8aHRRqAByMkpx+wysrN1gFj40DpcBxlYIZSzBFQXc5bQUiEjo1WU9tU1tXSgPYxdzS16UZle42BK0ZPDTtIuKgeXjAfCQ3By5AYiA0n04PH4oigJzO6SwjRyeTWqGKXl+qXOZSglSgKCQeW8NXqjWarXa3wwzx633e336AH4hpIMGNJpYZnN5osjvlvhtmGwdkJ9sSqpS6g0sti0F0XiymB97FLafSbJzhjzMHzprN0fMoMKVqKbOKtlKrgcllaUQDLkogA
π» Code
π Actual behavior
Error
'option' is possibly 'undefined'.
occursπ Expected behavior
No error
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: