The Wayback Machine - https://web.archive.org/web/20210414202118/https://github.com/microsoft/TypeScript/pull/42472
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

Exclude enum/number compatibility rule from comparable relation #42472

Merged
merged 3 commits into from Mar 6, 2021
Merged

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jan 24, 2021

Fixes #42442.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jan 24, 2021

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the extended test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jan 24, 2021

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jan 25, 2021

The only test changes related to this PR are some new errors in the RWC vscode project. All but one of them are flagging real issues. For example, code that declares something as a KeyCode[], but then compares element values to -1, which doesn't match any declared KeyCode member. So, the array declaration should really be (KeyCode | -1)[].

The one undesired new error is related to this enum declaration in vs/editor/common/modes.ts:

/**
 * Open ended enum at runtime
 * @internal
 */
export const enum LanguageId {
	Null = 0,
	PlainText = 1
}

The intent here is for LanguageId to be a numeric (i.e. non-union) enum. This can be accomplished by changing one of the enum values to a computed expression:

export const enum LanguageId {
	Null = +0,
	PlainText = 1
}

Subtle, but actually an intended and documented behavior.

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jan 25, 2021

This seems like almost pure goodness, but I would still err on the side of saying that this can wait for 4.3. That +0 workaround is pretty subtle.

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jan 25, 2021

What is the case for the non-union enum? It's unclear from that example.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jan 25, 2021

What is the case for the non-union enum? It's unclear from that example.

The code that broke compares a value of type LanguageId to the numeric value 73. I guess the intent is to create symbolic names for a few special language IDs, but otherwise allow any integer value.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jan 25, 2021

Let me know if https://github.com/microsoft/TypeScript/wiki/Breaking-Changes#union-enums-cannot-be-compared-to-any-number accurately reflects the change here.

Yes, looks good.

@sandersn sandersn added this to Not started in PR Backlog Feb 8, 2021
@ahejlsberg ahejlsberg merged commit f918bd9 into master Mar 6, 2021
10 of 11 checks passed
10 of 11 checks passed
build (10.x)
Details
CodeQL-Build CodeQL-Build
Details
CodeQL-Build CodeQL-Build
Details
build (12.x)
Details
build (14.x)
Details
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
CodeQL No new or fixed alerts
Details
license/cla All CLA requirements met.
Details
node10 Build #94101 succeeded
Details
node12 Build #94099 succeeded
Details
node14 Build #94100 succeeded
Details
PR Backlog automation moved this from Not started to Done Mar 6, 2021
@ahejlsberg ahejlsberg deleted the fix42442 branch Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PR Backlog
  
Done
Linked issues

Successfully merging this pull request may close these issues.

3 participants