Skip to content

28977 Fix const enum initializer error message #29030

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

Merged

Conversation

alisabzevari
Copy link
Contributor

Fixes #28977,

This is my first PR 😃
I updated the error message based on the suggestions in the issue and changed the baselines.

@@ -1696,7 +1696,7 @@
"category": "Error",
"code": 2473
},
"In 'const' enum declarations member initializer must be constant expression.": {
"const enum member initializers can only contain literal values and other const enums values.": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, now that I look at it, this is somewhat inaccurate because any computed enum is fair game:

enum E {
    A,
    B,
    C,
}

const enum F {
    // works
    A = E.A,
}

What about

const enum member initializers can only contain literal values and other computed enum values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will change the message.

BTW, wouldn't it make sense to provide some link to a page with samples and more detailed description in every error message? This error message already contains 2 Typescript terminologies (const enum initializer, computed enum values) which make it hard to understand. At least for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think down the line that might make sense, but I'd rather not do this for only one error message. I could imagine that down the line, diagnostics had an "documentation" field or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. This was an idea for all the error messages. Should I create an issue?

Copy link
Member

@DanielRosenwasser DanielRosenwasser Dec 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! We've been discussing it recently and aren't sure what the workflow should be like.

@DanielRosenwasser DanielRosenwasser merged commit f2806cd into microsoft:master Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants