Skip to content

Declaration for object with method named "new" incorrectly emitted with construct signature #55075

Closed
@jcalz

Description

@jcalz

Bug Report

🔎 Search Terms

declaration emit; method named "new"; construct signature

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about declaration emit, construct signatures
    (note: some of this actually changed between TS3.7 and TS3.8, but the behavior in TS3.7 still has the main problem)

⏯ Playground Link

Playground link with relevant code

💻 Code

export const a = {
  new(x: number) { return x + 1 }
}
export const b = {
  "new"(x: number) { return x + 1 }
}
export const c = {
  ["new"](x: number) { return x + 1 }
}

🙁 Actual behavior

The .d.ts file emitted is:

export declare const a: {
    new(x: number): number;
};
export declare const b: {
    new(x: number): number;
};
export declare const c: {
    new(x: number): number;
};

a construct signature that the actual object doesn't have. (For TS 3.7 and below, b and c are emitted as-is with quotes/brackets so there's no problem there. But a is still wrong.) If you consume this declaration weird things happen.

🙂 Expected behavior

Probably for this case new should be emitted as either "new" or ["new"] or something for all three cases:

export declare const a: {
    "new"(x: number): number;
};

Cross-linking to relevant Stack Overflow question

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions