Skip to content

Commit b149a47

Browse files
committed
Fixed bug with accessing length tuple property
Fixes #3
1 parent c150d24 commit b149a47

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/transformer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ function createTransformerFactory(program: ts.Program, options?: Partial<RenameO
249249

250250
// tslint:disable-next-line:cyclomatic-complexity
251251
function isTypePropertyExternal(type: ts.Type, typePropertyName: string): boolean {
252+
if (type.flags & ts.TypeFlags.Object) {
253+
const objectType = type as ts.ObjectType;
254+
// treat any tuple property as "external"
255+
if (objectType.objectFlags & ts.ObjectFlags.Tuple) {
256+
return true;
257+
}
258+
}
259+
252260
if (type.isUnionOrIntersection()) {
253261
const hasExternalSubType = type.types.some((t: ts.Type) => isTypePropertyExternal(t, typePropertyName));
254262
if (hasExternalSubType) {

tests/test-cases/tuple/input.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Tuple = [number, string] | [];
2+
3+
declare function getTuple(): Tuple;
4+
5+
export function doSomething(): void {
6+
console.log(getTuple().length);
7+
}

tests/test-cases/tuple/output.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
function doSomething() {
4+
console.log(getTuple().length);
5+
}
6+
exports.doSomething = doSomething;

0 commit comments

Comments
 (0)