-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesHelp WantedYou can do thisYou can do this
Milestone
Description
🔎 Search Terms
"javascript private static methods return type inference", "private static method inference error in declaration file"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about JavaScript private static methods return type inference.
⏯ Playground Link
💻 Code
foo.ts:
class Foo {
static #bar() { }
public static bar() {
return Foo.#bar;
}
}foo.d.ts:
declare class Foo {
#private;
static bar(): typeof Foo.__#1@#bar;
}🙁 Actual behavior
The foo.ts file will compile successfully without errors, but the generated foo.d.ts file will be incorrect because it contains a syntax error (Foo.__#1@#bar, ts(1005)).
As a result, any TypeScript subproject that depends on this compiled code will fail at compile time due to the invalid syntax in the foo.d.ts file.
🙂 Expected behavior
Enforce an explicit return type for the public static bar() method, as the presence of it currently allows bypassing this issue.
Otherwise, adjust how TypeScript infers the return types of JavaScript's private static methods.
Additional information about the issue
No response
robpalme
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesHelp WantedYou can do thisYou can do this