-
-
Notifications
You must be signed in to change notification settings - Fork 302
Resolve flow $Keys to union when typeParameter is an ObjectTypeAnnotation #290
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
Conversation
Refactored it a bit to use existing util function |
src/utils/getFlowType.js
Outdated
name: 'literal', | ||
value: getPropertyName(prop), | ||
})), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can consolidate this even more since I guess nodes of type ObjectExpression
and ObjectTypeAnnotation
are very similar. At the very least, can we extract an array of key names for them and process that?
Thank you for working on this! 😃 |
@fkling I updated I also noticed that the handleKeysHelper was resolving this to a union:
Which I don't believe is correct. See this example on the flow online repl. I removed this functionality and the associated test. |
Any other changes needed here? |
Sorry for the late reply. Thanks for working on this. I think we should leave the resolving of simple Identifiers in, as for example this could work: const obj = { a: 'a', b: 'b' }
type A = typeof obj;
const test: $Keys<A> = 'a' This should resolve correctly to the same result as if doing an inline ObjectExpression, but currently returns unknown. But this is an other problem we can fix separately, but let's leave the resolving of |
@danez for sure, just pushed those changes. |
Thank you very much. |
This adds support for ObjectTypeAnnotations as the typeParameter of $Keys.
This will now resolve to a union: