Skip to content

Commit 1871048

Browse files
andrewbranchRyanCavanaugh
authored andcommitted
Merge pull request #30734 from andrewbranch/bug/30664 (#30892)
Fall back from `globalReadonlyArrayType` to `globalArrayType` when transpiling
1 parent 7eb4739 commit 1871048

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30293,7 +30293,7 @@ namespace ts {
3029330293
autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
3029430294
}
3029530295

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

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
}

tests/baselines/reference/transpile/Supports as const arrays.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Supports as const arrays.oldTranspile.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Supports readonly keyword for arrays.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/transpile/Supports readonly keyword for arrays.oldTranspile.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)