Skip to content

[Bug]: Typescript error - A binding pattern parameter cannot be optional in an implementation signature #15396

@sebakerckhof

Description

@sebakerckhof

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

type TParams<T extends boolean> = {
  all?: T;
};

function foo({ all }: TParams<true>): string[];
function foo({ all }?: TParams<false>): string;
function foo({ all = false } = {}) {
  const results = ['a', 'b'];
  return all ? results : results[0];
}

Configuration file name

No response

Configuration

I use the online repl: https://babeljs.io/repl# with typescript enabled.

Current and expected behavior

This code is valid typescript according to TSC (4.9.4) and friends, but babel throws:
A binding pattern parameter cannot be optional in an implementation signature. (6:13)

Environment

I'm running it in the babel online repl: https://babeljs.io/repl (currently version: 7.20.14)

Possible solution

No response

Additional context

This compiles correctly with tsc

Metadata

Metadata

Labels

area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions