Repository navigation
Improve error on non-ambient class and function merge #32795
Description
Activity
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptHelp WantedYou can do thisYou can do thisDomain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancements
on Aug 9, 2019 austincummings commented
on Sep 12, 2019 ContributorMore actionsI can work on this one.
Reacted by Wesley Wighamaustincummings commented
on Sep 13, 2019 ContributorMore actionsWesley Wigham (@weswigham) here's the error message I've come up with. Any thoughts?
Class declaration cannot implement overload list for '{0}'. Function may have implementation or both class and function declarations must be ambient.weswigham commented
on Sep 13, 2019 MemberAuthorMore actionsAt at glance I'd say that looks good, but I'm wondering if the term
ambientis something we've used in an error message yet. Daniel Rosenwasser (@DanielRosenwasser) ?DanielRosenwasser commented
on Sep 13, 2019 MemberMore actionsAt a glance it's fine to say "ambient" as long as you have something actionable.
On the function:
Function with bodies can only merge with classes that are ambient.Related span on the class:
Consider adding a 'declare' modifier to this class.austincummings commented
on Sep 13, 2019 ContributorMore actionsDaniel Rosenwasser (@DanielRosenwasser) would that look something like this then? Or should the "Function with bodies..." messages only appear when hovering over the function name?
weswigham commented
on Sep 13, 2019 MemberAuthorMore actionsFunction with bodies can only merge with classes that are ambient.is supposed to be the primary error on the functions, instead ofClass declaration cannot implement overload list for '{0}'. Function may have implementation or both class and function declarations must be ambient.. The related spans are both supposed to be referring to the same thing.austincummings commented
on Sep 15, 2019 ContributorMore actionsThe related spans are both supposed to be referring to the same thing.
Wesley Wigham (@weswigham) sorry, I'm a bit confused as to what "same thing" refers to. Here's my understanding.
function Foo(): any; function Foo(n: number): any {} // ~~~ Function with bodies can only merge with classes that are ambient. // No related messages/spans? class Foo {} // ~~~ Class declaration cannot implement overload list for '{0}' // And related "Consider adding 'declare'..." referring to the span of this class?
weswigham commented
on Sep 15, 2019 MemberAuthorMore actionsThe
function Fooshould have the same related spans as the other error. Otherwise it looks good.Reacted by Austin Cummings

In #32584, we're allowing ambient classes and functions to merge, but non-ambient classes and functions still issue the same
Duplicate identifiererror. An improved, more specific, error would be useful. Something mentioning that either the function can have an implementation or both need to be ambient.