Don't emit binding pattern pattern / optional parameter error when an initializer is present #52880
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #50286
Before #50094, this code was fine because in TS, a question token and an initializer are mutually exclusive.
But after #50094, we now take into account optionality from JSDoc. But that means that we won't have a question token, and therefore can have an initializer, and that initializer can prevent a crash on call. So, we can just skip this error if there's an initializer; in TS code, this won't happen, but it fixes the issue for JS code.
This check is not type-aware. We could be smarter and use the new
parameterInitializerContainsUndefined
function I added in #52696 to detectundefined
(ornull
, with modification), but there's no point; we already emit a type error beforehand because we will check that the initializer is assignable to the binding pattern andundefined
ornull
are not.While here, use
isOptionalDeclaration
instead of checkingquestionToken
andisJSDocOptionalParameter
.