Incorrect diagnostic message in TS2814
🔎 Search Terms
2814, function body
🕗 Version & Regression Information
- regression at
v4.4.4.
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=4.4.4#code/MYGwhgzhAEBiD29oG9oChqegIzAJwEYAKAShWgF80q0AzAVwDtgAXAS3kbkVIG40A9AIB+APWgBRAEpSA8lIBccJqw5cA7mxYALHPAAmbAKYxgYLpxABPaAFsjeAOZHomndFCQIJ6DrAtofBcwW2xjRhYAOiA
💻 Code
// tests/cases/compiler/callOverloads1.ts
class Foo {
bar1() { }
}
function Foo();
//~^ error report: Function with bodies can only merge with classes that are ambient.
🙁 Actual behavior
The function Foo actually has no body (it's just a declaration), yet the error message says "Function with bodies...", which may be a bit confusing.
🙂 Expected behavior
Either show a hint like "Only functions can merge with ambient classes," or suppress the error report for functions without a body because class Foo will report Class declaration cannot implement overload list for 'Foo'.
Additional information about the issue
No response
FWIW function Foo(); is not valid syntax. You need the declare keyword and (with noImplictAny, a return type). Fixing this does not affect the other errors, though.
Hi, I've noticed that the diagnostic message for function declarations is misleading when there is no body. I plan to adjust the logic in checker.ts to check for function bodies and update the message in diagnosticMessages.json accordingly. Could you please assign this issue to me? Thank you!