Skip to content

Commit fe888b5

Browse files
author
Evgeniy Timokhov
committed
Fixed handling tuples when they are part of union/intersection
1 parent 4152e4d commit fe888b5

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/transformer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
296296
return true;
297297
}
298298

299+
if (objectType.objectFlags & ts.ObjectFlags.Reference) {
300+
const target = (objectType as ts.TypeReference).target;
301+
if (target !== objectType && isTypePropertyExternal(target, typePropertyName)) {
302+
return true;
303+
}
304+
}
305+
299306
// in case when we can't get where a property come from in mapped types
300307
// let's check the whole type explicitly
301308
// thus in case of when property doesn't have a declaration let's treat any property of a mapped type as "external" if its parent type is external
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type TwoItems = [number, number];
2+
type FourItems = [number, number, number, number];
3+
type TupleOrNumber = number | TwoItems | FourItems;
4+
5+
function drawRoundRect(tupleOrNumber: TupleOrNumber): void {
6+
if (!Array.isArray(tupleOrNumber)) {
7+
console.log(tupleOrNumber.toExponential());
8+
} else if (tupleOrNumber.length === 2) {
9+
const [first, second] = tupleOrNumber;
10+
console.log(first.toExponential(), second.toExponential());
11+
} else if (tupleOrNumber.length === 4) {
12+
const [first, second, third, fourth] = tupleOrNumber;
13+
console.log(first.toExponential(), second.toExponential(), third.toExponential(), fourth.toExponential());
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function drawRoundRect(tupleOrNumber) {
2+
if (!Array.isArray(tupleOrNumber)) {
3+
console.log(tupleOrNumber.toExponential());
4+
}
5+
else if (tupleOrNumber.length === 2) {
6+
var first = tupleOrNumber[0], second = tupleOrNumber[1];
7+
console.log(first.toExponential(), second.toExponential());
8+
}
9+
else if (tupleOrNumber.length === 4) {
10+
var first = tupleOrNumber[0], second = tupleOrNumber[1], third = tupleOrNumber[2], fourth = tupleOrNumber[3];
11+
console.log(first.toExponential(), second.toExponential(), third.toExponential(), fourth.toExponential());
12+
}
13+
}

0 commit comments

Comments
 (0)