Closed
Description
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