Uh oh!
There was an error while loading. Please reload this page.
fix35982: allow BigIntLiteral to parse as PropertyName for literal object and indices - #58608
Conversation
TypeScript Bot (typescript-bot)
commented
May 21, 2024
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure Daniel Rosenwasser (@DanielRosenwasser) and Ryan Cavanaugh (@RyanCavanaugh) are aware of the changes, just as a heads up. |
Isabel Duan (iisaduan)
commented
May 21, 2024
TypeScript Bot (@typescript-bot) test it |
TypeScript Bot (typescript-bot)
commented
May 21, 2024
Hey Isabel Duan (@iisaduan), the results of running the DT tests are ready. Everything looks the same! |
TypeScript Bot (typescript-bot)
commented
May 21, 2024
Isabel Duan (@iisaduan) Here are the results of running the user tests comparing Everything looks good! |
TypeScript Bot (typescript-bot)
commented
May 21, 2024
Isabel Duan (@iisaduan) Here they are:tscComparison Report - baseline..pr
System info unknown Hosts
Scenarios
Developer Information: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeScript Bot (typescript-bot)
commented
May 21, 2024
Isabel Duan (@iisaduan) Here are the results of running the top 400 repos comparing Everything looks good! |
Isabel Duan (iisaduan)
commented
May 23, 2024
TypeScript Bot (@typescript-bot) test it |
TypeScript Bot (typescript-bot)
commented
May 23, 2024
Hey Isabel Duan (@iisaduan), the results of running the DT tests are ready. Everything looks the same! |
TypeScript Bot (typescript-bot)
commented
May 23, 2024
Isabel Duan (@iisaduan) Here are the results of running the user tests comparing Everything looks good! |
TypeScript Bot (typescript-bot)
commented
May 24, 2024
Isabel Duan (@iisaduan) Here they are:tscComparison Report - baseline..pr
System info unknown Hosts
Scenarios
Developer Information: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeScript Bot (typescript-bot)
commented
May 24, 2024
Isabel Duan (@iisaduan) Here are the results of running the top 400 repos comparing Everything looks good! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Isabel Duan (iisaduan)
commented
Jul 13, 2024
TypeScript Bot (@typescript-bot) test it |
TypeScript Bot (typescript-bot)
commented
Jul 13, 2024
Hey Isabel Duan (@iisaduan), the results of running the DT tests are ready. Everything looks the same! |
TypeScript Bot (typescript-bot)
commented
Jul 13, 2024
Isabel Duan (@iisaduan) Here they are:tscComparison Report - baseline..pr
System info unknown Hosts
Scenarios
Developer Information: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TypeScript Bot (typescript-bot)
commented
Jul 13, 2024
Isabel Duan (@iisaduan) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Isabel Duan (iisaduan)
commented
Jul 13, 2024
TypeScript Bot (@typescript-bot) user test this |
TypeScript Bot (typescript-bot)
commented
Jul 13, 2024
Isabel Duan (@iisaduan) Here are the results of running the user tests with tsc comparing Everything looks good! |
| } | ||
| else { | ||
| error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); | ||
| const typeString = typeToString(indexNode.kind === SyntaxKind.BigIntLiteral ? getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(indexNode)) : indexType); |
There was a problem hiding this comment.
Does this just end up producing bigint or do we expect something else to show up here? If something other than bigint can appear, we should add tests as the tests only show bigint. If this can only ever produce bigint, then I would just use the literal string.
Also, unless anyone else has a particular preference, I think Type '1n' cannot be used as an index type is also acceptable, so leaving this as typeToString(indexType) might be fine.
There was a problem hiding this comment.
I'm not really sure how the latest push resolved this; "bigInt" isn't a thing in TS or JS and I think Ron was suggesting to actually write the value? (See also my comment on the earlier thread with suggested code)
There was a problem hiding this comment.
We should either write the value, or bigint (all lowercase) as it's the underlying base type.
There was a problem hiding this comment.
Sorry, I've been looking at the tests, and some of the test cases have been inconsistent with the caps. I'll fix that.
Would you prefer the "property does not exist on type" error? I was using the "bigint literal type cannot be used as an index" error because the original design choice was the bigintliteral type cannot be used as an index, as you should use a string or number instead. "cannot be used as index" seemed more descriptive of what was happening than "property does not exist".
I don't mind using the value in the error message (1n cannot be used as an index type) if you like that better, and it is what you would get with typeToString(indexType). I changed it because bigint made the above more clear as well.
There was a problem hiding this comment.
There was a problem hiding this comment.
I guess if you just swap it back to bigint, that should be sufficient. I see what you mean about the inconsistency; it's not that say 1n doesn't exist on the type, but that bigint isn't supported at all?
There was a problem hiding this comment.
Yes, it's valid syntactically in js to index with bigints, but we've disallowed them when type checking
Uh oh!
There was an error while loading. Please reload this page.
Daniel Rosenwasser (DanielRosenwasser)
left a comment
There was a problem hiding this comment.
There are a few things that I didn't catch before that I want addressed, but I'm going to mark this as approved so you're not blocked on merging.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fixes#35982
This PR allows more valid bigint uses in JS to parse and emit correctly. We will parse (and correctly emit) the following cases, but give the following errors: