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

dts doesn't resolve typescript paths on dts generation and wrong dts dist structure #19

Closed
D4RKAR117 opened this issue Aug 13, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@D4RKAR117
Copy link

Hello I'm trying to generate the .d.ts for my vite vue lib, but at the time that i inspect my dist folder i identify 2 problems so far:

  1. the .ts based .d.ts such as index.d.ts doesn't resolve correctly the typescript paths. eg. '@/' path. So module not found problem raises at the import and export of anything.

  2. The dist folder gets the intended declaration dir (in my case @types/), but have an incorrect folder structure for d.ts of my components. like copying the src/ dir inside. This maybe works alongside a correr path resolution buy i have no clue about it.

i have no idea if I'm misunderstanding something, or i have a wrong configuration for proper generation of types of my lib, so any advice is appreciated

For reproduction :

@qmhc
Copy link
Owner

qmhc commented Aug 14, 2021

The directory structure relative to root will be maintained when generating declaration files. This is to ensure the correct relationship of each type reference.

If you want a fixed export entry, you can use the insertTypesEntry option, otherwise you need to specify the type entry with types option in package.json.

In your case, first you need to remove declarationDir option in tsconfig.json (using outputDir instead) and change src/@types/index.d.ts to src/@types/index.ts (currently not support import type from .d.ts file), then add outputDir: '@types' to plugin options and run build script, finally add "types": "@types/src/index.d.ts" into package.json.

image

If you want to generate only a single declaration file in the end, I recommend @microsoft/api-extractor to you, use it after running build script to bundle declaration files.

@qmhc
Copy link
Owner

qmhc commented Aug 14, 2021

I will add support for import types from .d.ts files later.

@qmhc qmhc added the enhancement New feature or request label Aug 14, 2021
@D4RKAR117
Copy link
Author

Thanks for the fast answer, and the great advices.

The generation is much better with the changes made in this commit

also idk if is intended that @types is generated out dist with your advice, so y made outputDir to point inside dist, but maybe i misunderstood that part.

but my playground still failing with the import at src/index.d.ts. The typescript path @component is not resolved when is generated. Still like import VContainer from '@components/layout/container/VContainer.vue';. if this is related to the support that still WIP i will change to relative paths, but i like to have your confirmation first.

Thanks.

@qmhc
Copy link
Owner

qmhc commented Aug 14, 2021

There have some bugs, I open a new issue (#20) to track them.

Now you can change your alias config:

defineConfig({
  resolve: {
    alias: {
      '@components': path.resolve(__dirname, 'src/components'),
      '@': path.resolve(__dirname, 'src')
    }
  }
})

And use import { default as VContainer } from '@/components/layout/container/VContainer.vue' to solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants