-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix type definitions to fully support Typescript #6939
Fix type definitions to fully support Typescript #6939
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6100/ |
@@ -291,7 +294,11 @@ export const functionCommon = { | |||
optional: true, | |||
}, | |||
typeParameters: { | |||
validate: assertNodeType("TypeParameterDeclaration", "Noop"), | |||
validate: assertNodeType( |
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.
Guess one thing to think about, is that this change will make tSDeclareMethod
and tSDeclareFunction
(which spread in functionCommon
) accept TypeParameterDeclaration
.
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.
Good catch -- I missed that. Would you rather override the property for the TS types, or compose more granularly?
defineType("TSDeclareFunction", {
...functionCommon,
returnType {
...functionCommon.returnType
validate: ...etc
},
typeParameters: {
...functionCommon.typeParameters,
validate: ...etc.
}
});
vs.
export const functionCommon = {
// everything there now but returnType and typeAnnotation
}
// only used for core types that need to accept either Flow or TS nodes
const functionCommonWithTypes = {
returnType: {},
typeAnnotation: {}
}
I didn't see other examples of overriding spread properties in definintions -- if that's generally the case, then the second approach might be more consistent with the rest of the code.
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.
Yeah let's go with the second 👍
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.
@existentialism It's not immediately obvious because I squashed the commit, but this has been addressed.
I split the type annotations out of functionCommon
into functionTypeAnnotationCommon
, and spread both objects on the relevant core/es2015 types.
functionDeclarationCommon
and classMethodOrDeclareMethodCommon
still spread just functionCommon
. Types that use those now also spread either functionTypeAnnotationCommon
or tSFunctionTypeAnnotationCommon
as appropriate.
19e40bd
to
69db29b
Compare
… Typescript type definitions
69db29b
to
3bba280
Compare
@dpoindexter thanks again! |
This addresses missing or incorrect Typescript types in other type definitions.
For core, experimental, and ES2015 types, any type definition referencing a Flow node type (for example, the
typeParameters
property of theArrowFunctionExpression
node type) now also allows the equivalent Typescript node type. (In the case ofArrowFunctionExpression.typeParameters
, allowed types becameTypeParameterDeclaration | TSTypeParameterDeclaration | Noop
.For Typescript types, any type definition referencing a Flow node type replaced that reference with the equivalent Typescript node type. For example, in
TSInterfaceDeclaration.typeParameters
, allowed types becameTSTypeParameterDeclaration
rather thanTypeParameterDeclaration
.