-
Notifications
You must be signed in to change notification settings - Fork 12.8k
In JSDoc, parse postfix-? below conditional types/tuple types #39123
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Conversation
Outside of JSDoc comments, postfix-? is parsed at lower precedence than the `?` of conditional types, and a postfix-? inside a tuple type results in the type being marked optional. This PR changes JSDoc parsing to behave the same way, which means that 1. Conditional types are allowed in JSDoc. Fixes #37166. 2. Tuple types' postfix-? syntax is interpreted correctly in JSDoc. Fixes #38747. The breaking change is that a postfix-? type followed by another postfix type, like `[]` or `!`, is parsed as a conditional type. [Postfix-? is not common](#37166 (comment)), so this is an acceptable breaking change. A postfix-? type `T?` is still parsed everywhere else and treated as `T | null`.
@typescript-bot user test this -- let's see if any of Google's open source uses postfix-? |
@DanielRosenwasser pretty sure this is not going to break anyone -- think it should go into 4.0? |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
No changes to user tests! I think this is safe for 4.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -3356,7 +3356,7 @@ namespace ts { | |||
break; | |||
case SyntaxKind.QuestionToken: | |||
// If not in JSDoc and next token is start of a type we have a conditional type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment appears to be out of date?
Outside of JSDoc comments, postfix-? is parsed at lower precedence than the
?
of conditional types, and a postfix-? inside a tuple type results in the type being marked optional.This PR changes JSDoc parsing to behave the same way, which means that
The breaking change is that a postfix-? type followed by another postfix type, like
[]
or!
, is parsed as a conditional type. Postfix-? is not common, so this is an acceptable breaking change.A postfix-? type
T?
is still parsed everywhere else and treated asT | null
.