Skip to content

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

Development

Successfully merging this pull request may close these issues.

在 vite 的 preview 模式下 components.d.ts 文件被修改 有没有办法使 components.d.ts 中的类型定义只增不删?

2 participants