Skip to content
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

TypeScript "importsNotUsedAsValues" compiler option doesn't take effect while using path alias or baseUrl #1406

Closed
2 of 4 tasks
RageYL opened this issue Nov 11, 2021 · 5 comments

Comments

@RageYL
Copy link

RageYL commented Nov 11, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

import type { MyType } from 'mymodule';

generates

const mymodule_1 = require('...')

This problem was already reported in this closed issue: #783.

Minimum reproduction code

import { TypeA } from 'src/type-a'
import type { TypeB } from 'src/type-b'
import { TypeC } from './type-c'
import type { TypeD } from './type-d'
npm run build generates:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const type_a_1 = require("./type-a");
const type_b_1 = require("./type-b");

Steps to reproduce

https://github.com/RageYL/nest-cli-type-imports-bug

Expected behavior

No code should be emitted for type only imports.

Package version

8.1.2

NestJS version

8.1.2

Node.js version

14.17.6

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

From a quick google, we can skip the existing logic in https://github.com/nestjs/nest-cli/blob/master/lib/compiler/hooks/tsconfig-paths.hook.ts#L18 with the following edit:

-          tsBinary.isImportDeclaration(node) ||
+          (tsBinary.isImportDeclaration(node) && !node.importClause?.isTypeOnly) ||
```
@jmcdo29
Copy link
Member

jmcdo29 commented Nov 11, 2021

Can you make a git repo with the steps to reproduce, so we can just clone, install, and verify the issue?

@RageYL
Copy link
Author

RageYL commented Nov 11, 2021

Created a repo from scratch using @nestjs/cli and edited the main file: https://github.com/RageYL/nest-cli-type-imports-bug

@liaoyinglong
Copy link

has anything news?

@jmcdo29
Copy link
Member

jmcdo29 commented Dec 10, 2021

This slipped my radar for a bit, sorry about that. The reproduction does indeed reproduce and shows tsc working as expected, and the proposed code change does fix up nest build so that it acts like tsc in this case. I'll get a PR made for fixing this done today

liaoyinglong added a commit to liaoyinglong/nest-cli that referenced this issue Dec 12, 2021
@kamilmysliwiec
Copy link
Member

Let's track this here #1449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants