-
Notifications
You must be signed in to change notification settings - Fork 12.8k
keyof
inconsistent between primitive types
#56876
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
Comments
Effectively same issue as #30225. |
|
Ah, looking at #30225 again I see what you mean. To get const aObject = {x:1}
const aObjectAsObject = aObject as (typeof aObject & Object)
'toString' satisfies keyof typeof aObjectAsObject Do you know if there's any way to have |
That's all 100% intentional:
It's also worth noting that |
That makes sense, and it appears this is at the very least an instance of under-documentation of what Edit: I found a reference in this comment to "apparent type" and a mention in this deprecated handbook but nothing current.
Yes, that is a correct inference, and it means "this has one typed property If the type does not contain Circling back to the original issue, how can |
I don't know why we put |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
keyof, primitive
π Version & Regression Information
keyof
β― Playground Link
https://www.typescriptlang.org/play?target=9&jsx=0&ts=5.4.0-dev.20231225#code/PTAEBcAsFMGdtAYwIb1qAZsglgG1NgHagAqAngA7QDKiATtheKAKwB0ALGwAwC0AJtABuAKBGIA9oVjNkAeQBGAK2iJmAXlABvAB4AuAIwBfEQHJwE6uAaEA5qdCxk4bLAzY4oANbQyEjBCU0P6g8sqq4GKS0rIAYgCuhGrYUqCaABQAlOoAfFom5pbWRPaOzq7unj5+AeBBIcgJSS5SUVIyoQBCEhL4mtbx0GYWVjalTi5uHujVIXVUDd29YiAQMJi9uBIA7iVIqJ7IuPiw8YiI0ND8bTGhAIJ0dMhkaaAA2oTxxwC6w0VjDgmFWm3l8c3qAWQDyeZBuHWQoz2mgARMi-oi7IDylMqmDahDQhjbHDZAA5eIAWwU0DorwM6OKmLKk0qMzxgQWkPJVJpJK62FsAElCBpQBwAEyEBkA5nA3E1DnBSGdAXCyLidqyahkKm9V7a3W4dIcTLSkpYlkg2b4zmEnUKXpAA
π» Code
π Actual behavior
toString
is in the key type of arrays, strings, numbers, bigints, and symbolstoString
is NOT in the key type of objects, functions, and boolsπ Expected behavior
I expect
keyof
to either always includetoString
or never includetoString
(not sure which).Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: