-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow satisfies keyof
assertions in computed property names
#58829
base: main
Are you sure you want to change the base?
Conversation
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 @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@typescript-bot pack this |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
That's not actually my main complaint, it's a more general concern than that. tl;dr This feels like a confusing overloading of the
If you do go that route, then I'd suggest to go all the way and just make |
I think logically class Foo {
[deferred x]: ...;
}
vs
class Foo {
[x satisfies keyof]: ...;
} |
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.