Skip to content

Declaration files paths not being transformed when using 'import type...' #73

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

Closed
lukemorales opened this issue Oct 22, 2020 · 17 comments
Closed

Comments

@lukemorales
Copy link

lukemorales commented Oct 22, 2020

I've been struggling with the generated declaration files paths not being transformed to relative paths and I was using i.e import type { Type } from '@/common/types'.
I removed all import type {} and replaced with the standard import { Type } from '@/common/types' and it transformed correctly in the declaration files, so there seems to be a problem resolving the import type syntax 🤔

@lukemorales lukemorales changed the title Declaration files aliases not transformed when using 'import type...' Declaration files paths not being transformed when using 'import type...' Oct 22, 2020
@nonara
Copy link
Collaborator

nonara commented Oct 22, 2020

Thanks for the report, Luke. What version of TS are you using?

@lukemorales
Copy link
Author

@nonara TS version 4.0.3, latest available in VSCode

@nonara
Copy link
Collaborator

nonara commented Oct 22, 2020

I can't reproduce on this end.

The following transforms properly for me:

root-dir/file1.ts

export type A = string;

index.ts

import type { A as ATypeOnly } from '#root/file1'
export { ATypeOnly }

Can you create a reproduction?

@nonara
Copy link
Collaborator

nonara commented Oct 23, 2020

I've added tests to ensure type-only import works, and everything seems to be ok. Are you using v2+?

If you can find a way to reproduce with two files, please let me know and I'll look into it.

@nonara
Copy link
Collaborator

nonara commented Nov 17, 2020

Closing for housekeeping. Feel free to comment if you think this was in error.

@nonara nonara closed this as completed Nov 17, 2020
@saqirmdevx
Copy link

saqirmdevx commented Aug 20, 2022

Hello i got same issue here with latest version of Typescript and your plugin

Screenshot 2022-08-20 at 14 09 22

Javascript (Compiled import version)
Screenshot 2022-08-20 at 14 11 12

Basically "import type" remains in the file while it should be removed.

This is typescript file
Screenshot 2022-08-20 at 14 12 05

@danielpza
Copy link
Member

@saqirmdevx Can you share your tsconfig.json configuration? What typescript and typescript-transform-paths versions are you using?

npm ls typescript
npm ls typescript-transform-paths

@nonara
Copy link
Collaborator

nonara commented Oct 10, 2022

It's possible that the latest TypeScript has updated something involving Type Elision. We had to replicate this functionality locally.

@saqirmdevx Can you share a small reproduction repo?

@danielpza Good to see you again, Daniel! How've you been?

@saqirmdevx
Copy link

saqirmdevx commented Oct 10, 2022

@saqirmdevx Can you share your tsconfig.json configuration? What typescript and typescript-transform-paths versions are you using?

npm ls typescript
npm ls typescript-transform-paths

Hello!

I am sorry i already using different method (i created custom script that update paths after compilation).
I can't remember exactly what tsconfig and version.

I believe tsconfig is unchanged: (Paths might be different)

{
  "compilerOptions": {
    /* Basic Options */
    "target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
    "module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
    "outDir": "build" /* Redirect output structure to the directory. */,
    "rootDir": "../" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
    "removeComments": true /* Do not emit comments to output. */,
    /* Strict Type-Checking Options */
    "strict": true /* Enable all strict type-checking options. */,

    /* Additional Checks */
    "noUnusedLocals": true /* Report errors on unused locals. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,

    /* Module Resolution Options */
    "moduleResolution": "node",
    "baseUrl": ".",
    "esModuleInterop": true,
  
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "include": [
    "src/**/*.ts",
    "../shared/*.ts"
  ],
  "exclude": [ "../client/**"]
}

I was using latest typescript (stable version) and latest typescript-transform-paths.

@patrickkunka
Copy link

I am currently also experiencing the issue as described by @saqirmdevx whereby import type ... statements are present in JS output.

typescript: 4.8.4
typescript-transform-paths: 3.3.1

@nonara
Copy link
Collaborator

nonara commented Oct 10, 2022

Thanks, all. Sounds like an issue with new TS. I'll have a look.

@patrickkunka
Copy link

Not sure if related, but I see the following warning in the console when I run tsc with the plugin applied:

DeprecationWarning: 'updateImportTypeNode' has been deprecated since v4.6.0. Use the overload that accepts 'assertions'

@nonara
Copy link
Collaborator

nonara commented Oct 21, 2022

This issue has been resolved in v3.4!

@patrickkunka
Copy link

Brilliant, I will give it a whirl next week

@patrickkunka
Copy link

Apologies for the delay. I just tried version 3.4.4 but the issue still persists. There are import type ... statements in the compiled JS output.

@nonara
Copy link
Collaborator

nonara commented Nov 23, 2022

@patrickkunka What version of TS? If it's 4.9, there's an issue affecting most transformers, including this. In that case it would not work at all.

If the problem happens with ts 4.8, if you can provide a quick repro, I will check it out. The issues reported in this thread were definitely corrected, so I'd have to dig in to see what you're facing.

@patrickkunka
Copy link

patrickkunka commented Nov 23, 2022

Hi @nonara it's still 4.8.4 as reported above. I'll try to create an isolated repro for you today.

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

5 participants