Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report an error like TS2713 for enum members and provide a corresponding code fix #20358

Closed
amcasey opened this issue Nov 30, 2017 · 7 comments
Closed
Labels
Domain: Error Messages The issue relates to error messaging Good First Issue Well scoped, documented and has the green light Help Wanted You can do this PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19 Suggestion An idea for TypeScript
Milestone

Comments

@amcasey
Copy link
Member

amcasey commented Nov 30, 2017

    enum Color {
        Red,
        Green,
        Blue
    }

    let a1: Color.Red.toString; // TS2694: The Namespace 'Color' has no exported member 'Red'
    let a2: Color.Red["toString"];

The type of a1 is invalid - it should be like the type of a2. It would be nice if the error indicated as much (which would also allow us to offer a code fix).

@amcasey amcasey added the Suggestion An idea for TypeScript label Nov 30, 2017
@amcasey
Copy link
Member Author

amcasey commented Nov 30, 2017

FYI @DanielRosenwasser

@mhegazy mhegazy added Domain: Error Messages The issue relates to error messaging Help Wanted You can do this Good First Issue Well scoped, documented and has the green light labels Nov 30, 2017
@mhegazy mhegazy added this to the Community milestone Jan 4, 2018
@remojansen
Copy link
Contributor

remojansen commented Jan 11, 2018

Hi @mhegazy

I would like to try to work on this issue. The error TS2713 reads:

Cannot access '{0}.{1}' because '{0}' is a type, but not a namespace. Did you mean to retrieve the type of the property '{1}' in '{0}' with '{0}["{1}"]'?

How should the new error look like? Should it be a new error or TS2713 is enough?

Cannot access 'Red.toString' because 'Red' is a type, but not a namespace. Did you mean to retrieve the type of the property 'toString' in 'Red' with 'Red["toString"]'?

Thanks!

@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2018

//cc @DanielRosenwasser for feedback here.

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@sandersn sandersn added the PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19 label Sep 18, 2020
@ayip10
Copy link

ayip10 commented Oct 1, 2020

this issue is being looked at for ghcOSD!

@yehee
Copy link

yehee commented Jan 29, 2021

@ayip10 Hi! I was looking into the issue just now and wondering if this has already been worked on. Thanks!

@abuob
Copy link
Contributor

abuob commented Nov 19, 2022

Currently going through "Good first issue"-labels and stumbled over this one; I think this issue can be closed, it seems outdated?
The error is currently reported like this (not anymore as in the initial description):

enum Color {
    Red,
    Green,
    Blue
}

let a1: Color.Red.toString; // 'Color.Red.toString' refers to a value, but is being used as a type here. Did you mean 'typeof Color.Red.toString'? (2749)
let a2: Color.Red["toString"];

Playground Link
The new error seems "good enough"?

@jakebailey
Copy link
Member

Just looking at old issues; I definitely agree with the above. This was fixed by #45354 in the same was as #45333.

And as Daniel said in that PR:

I think we'd really like to suggest typeof Color.Red.toString first if that would be valid, then fall back to using indexed access syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Good First Issue Well scoped, documented and has the green light Help Wanted You can do this PursuitFellowship Help wanted from Pursuit fellowship; others please avoid until Dec 19 Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

9 participants