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

fix: lose components types of components.d.ts #447

Merged
merged 1 commit into from Jul 6, 2022
Merged

fix: lose components types of components.d.ts #447

merged 1 commit into from Jul 6, 2022

Conversation

ycs77
Copy link
Contributor

@ycs77 ycs77 commented Jul 5, 2022

fix #403
fix #419

  1. The options.dts is unresolved, if the user not setting dts then will return undefined (not default value true), so must be use from the resolved option ctx.options.dts.
  2. The ctx.generateDeclaration() can't resolve the UI components (get from resolvers) on first call on startup dev server, whether UI components in the components.d.ts exists or not, will be removed on startup dev server.

This PR changes to generate .d.ts file on startup server if ctx.options.dts is true and the file (like components.d.ts) exists.

(Of course, components.d.ts will still be updated normally when adding, updating files or trigger transform hook.)


No fix:

components.d.ts (before startup server):

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
    VanRate: typeof import('vant/es')['Rate']
  }

}

Start dev/preview server if no setting options.dts:

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
    VanRate: typeof import('vant/es')['Rate']
  }

}

Start dev/preview server if setting options.dts to true:

Warning

Missing VanRate (and other UI components) component type, the #403, #419 both is this status.

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
  }

}

Apply PR (fixed):

components.d.ts (before startup server):

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
    VanRate: typeof import('vant/es')['Rate']
  }

}

Start dev/preview server if no setting options.dts:

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
    VanRate: typeof import('vant/es')['Rate']
  }

}

Start dev/preview server if setting options.dts to true:

declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    ComponentA: typeof import('./src/components/ComponentA.vue')['default']
    VanRate: typeof import('vant/es')['Rate']
  }

}

@ycs77 ycs77 requested a review from antfu as a code owner July 5, 2022 15:47
@ycs77 ycs77 changed the title fix: missing types in components.d.ts fix: lose types in components.d.ts Jul 5, 2022
@ycs77 ycs77 changed the title fix: lose types in components.d.ts fix: lose types of components.d.ts Jul 5, 2022
@ycs77 ycs77 changed the title fix: lose types of components.d.ts fix: lose components types of components.d.ts Jul 5, 2022
@antfu antfu merged commit 55914b5 into unplugin:main Jul 6, 2022
@ycs77 ycs77 deleted the fix-loss-dts-types branch July 6, 2022 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants