TypeScript: trailing commas after rest parameters in ambient contexts

Bug Report

Current behavior

Currently, Babel throws an unrecoverable syntax error whenever it finds a trailing comma after a rest parameter, however TypeScript allows such commas in ambient contexts (in declarations marked with declare or in .d.ts files).

Input Code

// in a .ts file
declare function foo(...args: any[],): any;

declare class Bar {
    foo(...args: any[],): any
}

declare interface Baz {
    foo(...args: any[],): any
}

declare type Q = (...args: any[],) => any

// in a .d.ts file
function foo(...args: any[],): any;

class Bar {
    foo(...args: any[],): any
}

interface Baz {
    foo(...args: any[],): any
}

type Q = (...args: any[],) => any

Expected behavior

No error

Environment

  • Babel version(s): v7.13.14

1 possible answer(s) on “TypeScript: trailing commas after rest parameters in ambient contexts