Allow satisfies keyof
assertions in computed property names
#58829
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.
Fixes #58800
This implements the proposal in the linked issue, along with the addendum about invalid
satisfies keyof
property types still getting unique, singular property names (which ensures declaration file output always includes the computed names, even when they don't resolve).We can still bikeshed the syntax if anyone really wants, but I think this probably fits the bill without actually introducing anything too far off of what we already allow. Though yes, 15 characters is a lot - that's
satisfies
for you.The open question I think worth answering is if
satisfies keyof
should be allowed in all expression positions and not just in computed property names. It's certainly at least useful as a shorthand forsatisfies (string | number | symbol)
(though the check should be a wee bit stronger than that, since it also checks unit-ness), which has a similar effect on literals toas const
, without readonly-ing or const-ing array/object types (and instead erroring on them). It's probably worth noting, while generics are generally forbidden, givenT extends "a" | "b"
,T & "a"
simplifies to"a"
under current rules, so presents as a unit type - making it the only generic form, afaik, that can pass the unit-type-key check.