Skip to content

Commit 29a1a17

Browse files
authored
fix(type-compiler): set ts compiler options target to es2022 if higher than es20222 when resolving global lib files (#516)
1 parent e405ed3 commit 29a1a17

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/type-compiler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dependencies": {
3939
"@deepkit/type-spec": "^1.0.1-alpha.108",
4040
"@marcj/ts-clone-node": "^2.0.0",
41-
"@typescript/vfs": "^1.4.0",
41+
"@typescript/vfs": "1.5.0",
4242
"get-tsconfig": "^4.5.0",
4343
"lz-string": "^1.4.4",
4444
"micromatch": "^4.0.5",

packages/type-compiler/src/compiler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1883,11 +1883,11 @@ export class ReflectionTransformer implements CustomTransformer {
18831883

18841884
//todo also read compiler options "types" + typeRoot
18851885

1886-
//currently knownLibFilesForCompilerOptions from @typescript/vfs doesn't return correct lib files for ES2022,
1887-
//so we switch here to es2021 if bigger than es2021.
1886+
//currently knownLibFilesForCompilerOptions from @typescript/vfs doesn't return correct lib files for esnext,
1887+
//so we switch here to es2022 if bigger than es2022.
18881888
const options = { ...this.compilerOptions };
1889-
if (options.target && (options.target > ScriptTarget.ES2021 && options.target < ScriptTarget.ESNext)) {
1890-
options.target = ScriptTarget.ES2021;
1889+
if (options.target && (options.target === ScriptTarget.ESNext)) {
1890+
options.target = ScriptTarget.ES2022;
18911891
}
18921892
const libs = knownLibFilesForCompilerOptions(options, ts);
18931893

packages/type-compiler/tests/transpile.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ test('resolve import ts', () => {
2222
expect(res.logger).toContain('Logger.__type =');
2323
});
2424

25+
test('use global types with esnext target', () => {
26+
const res = transpile({
27+
'app': `
28+
interface User {}
29+
export type a = Partial<User>;
30+
`
31+
}, {
32+
target: ts.ScriptTarget.ESNext,
33+
});
34+
35+
expect(res.app).toContain('const __ΩPartial = ');
36+
expect(res.app).toContain('() => __ΩPartial');
37+
});
38+
2539
test('resolve import d.ts', () => {
2640
const res = transpile({
2741
'app': `

packages/type-compiler/tests/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function transform(files: Record<string, string>, options: ts.CompilerOpt
6565
* The first entry in files is executed as main script
6666
*/
6767
export function transpileAndRun(files: Record<string, string>, options: ts.CompilerOptions = {}): any {
68-
const source = transpile(files);
68+
const source = transpile(files, options);
6969
console.log('transpiled', source);
7070
const first = Object.keys(files)[0];
7171

0 commit comments

Comments
 (0)