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:
beraliv
2020-04-15 22:47:28 +03:00
committed by GitHub
parent c85aafdff6
commit 6b8f6ab2de
11 changed files with 170 additions and 9 deletions

View File

@@ -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,