Skip to content

fix(type-compiler): set ts compiler options target to es2022 if esnext when resolving global lib files #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 6 additions & 207 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/type-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@deepkit/type-spec": "^1.0.1-alpha.108",
"@marcj/ts-clone-node": "^2.0.0",
"@typescript/vfs": "^1.4.0",
"@typescript/vfs": "1.5.0",
"get-tsconfig": "^4.5.0",
"lz-string": "^1.4.4",
"micromatch": "^4.0.5",
Expand Down
8 changes: 4 additions & 4 deletions packages/type-compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,11 +1881,11 @@ export class ReflectionTransformer implements CustomTransformer {

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

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

Expand Down
14 changes: 14 additions & 0 deletions packages/type-compiler/tests/transpile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ test('resolve import ts', () => {
expect(res.logger).toContain('Logger.__type =');
});

test('use global types with esnext target', () => {
const res = transpile({
'app': `
interface User {}
export type a = Partial<User>;
`
}, {
target: ts.ScriptTarget.ESNext,
});

expect(res.app).toContain('const __ΩPartial = ');
expect(res.app).toContain('() => __ΩPartial');
});

test('resolve import d.ts', () => {
const res = transpile({
'app': `
Expand Down
Loading