[ts] Allow optional binding pattern parameters within types/interfaces (#12227)

This commit is contained in:
Brian Ng
2020-10-21 08:16:43 -05:00
committed by GitHub
parent ddb7e05f07
commit d51aa6d761
8 changed files with 432 additions and 2 deletions

View File

@@ -2573,7 +2573,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Allow type annotations inside of a parameter list.
parseAssignableListItemTypes(param: N.Pattern) {
if (this.eat(tt.question)) {
if (param.type !== "Identifier" && !this.state.isDeclareContext) {
if (
param.type !== "Identifier" &&
!this.state.isDeclareContext &&
!this.state.inType
) {
this.raise(param.start, TSErrors.PatternIsOptional);
}