Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFix type definitions to fully support Typescript #6939
Conversation
This comment has been minimized.
This comment has been minimized.
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( |
This comment has been minimized.
This comment has been minimized.
existentialism
Dec 1, 2017
•
Member
Guess one thing to think about, is that this change will make tSDeclareMethod
and tSDeclareFunction
(which spread in functionCommon
) accept TypeParameterDeclaration
.
This comment has been minimized.
This comment has been minimized.
dpoindexter
Dec 1, 2017
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dpoindexter
Dec 4, 2017
Author
Contributor
@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
… Typescript type definitions
69db29b
to
3bba280
This comment has been minimized.
This comment has been minimized.
@dpoindexter thanks again! |
dpoindexter commentedNov 30, 2017
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
.