Skip to content

Invalid type declaration for Class Instance Method inside a .js file with a default value of an inner parameter #36507

Closed
@ghost

Description

TypeScript Version: 3.7.5 and 3.8.0-dev.20200128

Search Terms: "default value" parameter "type definition"

Code

tsc --allowJs --declaration --outDir out x.js

x.js:

export class Z {
  f(x = 1, y) {
    return [x, y];
  }
}

Expected behavior:

x.d.ts should be:

export class Z {
    f(x: number | undefined, y: any): any[];
}

Actual behavior:

x.d.ts contains invalid typescript:

export class Z {
    f(x?: number, y: any): any[];
}

Playground Link: Playground Link

Related Issues: None

Notes: Both top-level functions (in either .js or .ts) and class instance methods in .ts files have correct type defs generated in both 3.7.5 and 3.8.0-dev.20200128

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions