transform-spread: create TS types (not Flow) when using TS (#11378)
* ➕ add test fixture * ➕ add removeTypeDuplicates for typescript * ➕ add createTSUnionType for typescript * 💊 fix ConditionalExpression for typescript * 💊 fix ConditionalExpression * 💊 fix added test case * ➕ add new line at the end of the file * 💊 types.every(f) => f(types[0]) * 🔄 bug => foo * ➕ add TSBaseType * ➕ add conditions NOT to break backward compatibility
This commit is contained in:
@@ -91,9 +91,15 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
return t.createUnionTypeAnnotation(types);
|
||||
if (!types.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
|
||||
return t.createTSUnionType(types);
|
||||
}
|
||||
|
||||
return t.createUnionTypeAnnotation(types);
|
||||
}
|
||||
|
||||
function getConstantViolationsBefore(binding, path, functions) {
|
||||
@@ -201,6 +207,13 @@ function getConditionalAnnotation(binding, path, name) {
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
|
||||
return {
|
||||
typeAnnotation: t.createTSUnionType(types),
|
||||
ifStatement,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
typeAnnotation: t.createUnionTypeAnnotation(types),
|
||||
ifStatement,
|
||||
|
||||
Reference in New Issue
Block a user