镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Improve error on non-ambient class and function merge #32795

Description

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

Activity

  1. austincummings commented on Sep 12, 2019

    @austincummings
    Contributor

    I can work on this one.

  2. austincummings commented on Sep 13, 2019

    @austincummings
    Contributor

    Wesley 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.

  3. weswigham commented on Sep 13, 2019

    @weswigham
    MemberAuthor

    At at glance I'd say that looks good, but I'm wondering if the term ambient is something we've used in an error message yet. Daniel Rosenwasser (@DanielRosenwasser) ?

  4. DanielRosenwasser commented on Sep 13, 2019

    @DanielRosenwasser
    Member

    At 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.

  5. austincummings commented on Sep 13, 2019

    @austincummings
    Contributor

    Daniel Rosenwasser (@DanielRosenwasser) would that look something like this then? Or should the "Function with bodies..." messages only appear when hovering over the function name?

    image

  6. weswigham commented on Sep 13, 2019

    @weswigham
    MemberAuthor

    Function with bodies can only merge with classes that are ambient. is supposed to be the primary error on the functions, instead of Class 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.

  7. austincummings commented on Sep 15, 2019

    @austincummings
    Contributor

    The 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?
  8. weswigham commented on Sep 15, 2019

    @weswigham
    MemberAuthor

    The function Foo should have the same related spans as the other error. Otherwise it looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions