Skip to content

Commit 9475bf7

Browse files
committed
Fall back from globalReadonlyArrayType to globalArrayType when transpiling
1 parent 5869662 commit 9475bf7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30307,7 +30307,7 @@ namespace ts {
3030730307
autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
3030830308
}
3030930309

30310-
globalReadonlyArrayType = <GenericType>getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1);
30310+
globalReadonlyArrayType = <GenericType>getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1) || globalArrayType;
3031130311
anyReadonlyArrayType = globalReadonlyArrayType ? createTypeFromGenericGlobalType(globalReadonlyArrayType, [anyType]) : anyArrayType;
3031230312
globalThisType = <GenericType>getGlobalTypeOrUndefined("ThisType" as __String, /*arity*/ 1);
3031330313

src/testRunner/unittests/services/transpile.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,5 +445,13 @@ var x = 0;`, {
445445
}
446446
}
447447
});
448+
449+
transpilesCorrectly("Supports readonly keyword for arrays", "let x: readonly string[];", {
450+
options: { compilerOptions: { module: ModuleKind.CommonJS } }
451+
});
452+
453+
transpilesCorrectly("Supports 'as const' arrays", `([] as const).forEach(k => console.log(k));`, {
454+
options: { compilerOptions: { module: ModuleKind.CommonJS } }
455+
});
448456
});
449457
}

0 commit comments

Comments
 (0)