-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix(checker): Allow element access expressions in computed property names if argument is literal #62968
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
Open
kairosci
wants to merge
9
commits into
microsoft:main
Choose a base branch
from
kairosci:fix/enum-computed-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(checker): Allow element access expressions in computed property names if argument is literal #62968
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e813bb0
fix(checker): Allow element access expressions in computed property n…
kairosci 74055e7
Merge branch 'main' into fix/enum-computed-keys
kairosci 69bcbc4
Merge branch 'main' into fix/enum-computed-keys
kairosci 91424d8
fix(checker): Allow element access expressions in computed property n…
kairosci 5e9b706
Merge branch 'main' into fix/enum-computed-keys
kairosci d1fff11
Merge branch 'main' into fix/enum-computed-keys
kairosci 598f80f
Merge branch 'main' into fix/enum-computed-keys
kairosci a5d0446
Merge branch 'main' into fix/enum-computed-keys
kairosci 415baaa
fix: correct isLateBindableAST to pass entire ElementAccessExpression
kairosci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/declarationEmitLateBoundAssignments.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| declarationEmitLateBoundAssignments.ts(4,1): error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'typeof foo'. | ||
| Property '[_private]' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(6,1): error TS7053: Element implicitly has an 'any' type because expression of type '"strMemName"' can't be used to index type 'typeof foo'. | ||
| Property 'strMemName' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(8,1): error TS7053: Element implicitly has an 'any' type because expression of type '"dashed-str-mem"' can't be used to index type 'typeof foo'. | ||
| Property 'dashed-str-mem' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(10,1): error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof foo'. | ||
| Property '42' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(12,19): error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'typeof foo'. | ||
| Property '[_private]' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(13,19): error TS7053: Element implicitly has an 'any' type because expression of type '"strMemName"' can't be used to index type 'typeof foo'. | ||
| Property 'strMemName' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(14,19): error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof foo'. | ||
| Property '42' does not exist on type 'typeof foo'. | ||
| declarationEmitLateBoundAssignments.ts(15,19): error TS7053: Element implicitly has an 'any' type because expression of type '"dashed-str-mem"' can't be used to index type 'typeof foo'. | ||
| Property 'dashed-str-mem' does not exist on type 'typeof foo'. | ||
|
|
||
|
|
||
| ==== declarationEmitLateBoundAssignments.ts (8 errors) ==== | ||
| export function foo() {} | ||
| foo.bar = 12; | ||
| const _private = Symbol(); | ||
| foo[_private] = "ok"; | ||
| ~~~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property '[_private]' does not exist on type 'typeof foo'. | ||
| const strMem = "strMemName"; | ||
| foo[strMem] = "ok"; | ||
| ~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '"strMemName"' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property 'strMemName' does not exist on type 'typeof foo'. | ||
| const dashStrMem = "dashed-str-mem"; | ||
| foo[dashStrMem] = "ok"; | ||
| ~~~~~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '"dashed-str-mem"' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property 'dashed-str-mem' does not exist on type 'typeof foo'. | ||
| const numMem = 42; | ||
| foo[numMem] = "ok"; | ||
| ~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property '42' does not exist on type 'typeof foo'. | ||
|
|
||
| const x: string = foo[_private]; | ||
| ~~~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property '[_private]' does not exist on type 'typeof foo'. | ||
| const y: string = foo[strMem]; | ||
| ~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '"strMemName"' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property 'strMemName' does not exist on type 'typeof foo'. | ||
| const z: string = foo[numMem]; | ||
| ~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property '42' does not exist on type 'typeof foo'. | ||
| const a: string = foo[dashStrMem]; | ||
| ~~~~~~~~~~~~~~~ | ||
| !!! error TS7053: Element implicitly has an 'any' type because expression of type '"dashed-str-mem"' can't be used to index type 'typeof foo'. | ||
| !!! error TS7053: Property 'dashed-str-mem' does not exist on type 'typeof foo'. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check in the while loop is too restrictive. It should also allow EntityNameExpression (identifier or property access) as arguments, not just literals.
The current code only accepts string/numeric literals or signed numeric literals, which breaks late-bound property assignments like
foo[_private] = "ok"where_privateis an identifier variable.The condition should be:
This allows both the new use case (
Enum['key']with literal arguments) and the existing use case (foo[symbol]with identifier arguments).