-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
TS 4.2 beta preserves "keyof" expressions in type display #42322
Comments
When there are two keys, it's probably preferable, but what about when there are a hundred? It's less clear then, and losing the information about where those keys are coming from is less recoverable. As a developer I can go to the definition of |
Fair enough, but with TS 4.2 is there any way to expand the type so that I can see what it actually is? The interface Point {
x: number;
y: number;
}
type Axes = keyof Point;
// type is keyof Point
type AxesExpand = unknown & Axes;
// type is keyof Point
type AxesExpand2 = unknown & keyof Point;
// type is keyof Point |
Or type Q = Exclude<Axes, never>; |
Thanks @RyanCavanaugh ! |
There is also the useful Edit: Or even, as they are related, a The
is a really good argument, but should be easier for new devs to know how they can "simplify" their types when wanted, as it really improves the DX some times. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
playground
π» Code
Mouse over
Axes
.π Actual behavior
Displays
keyof Point
π Expected behavior
Displays
"x" | "y"
.I assume this is the result of #42284, but this display seems much less informative than what we used to have:
Having used
keyof
in the past, I know thatkeyof Point
is the same as"x" | "y"
. But displaying its type askeyof Point
isn't very informative if you don't know that. I worry that this will make it much harder for new TypeScript users to understand howkeyof
works.The text was updated successfully, but these errors were encountered: