From efe0a879f34ba0bc864de9cf599f3ce5a5061a31 Mon Sep 17 00:00:00 2001 From: Wenfang Du Date: Mon, 5 Jun 2023 20:05:55 +0800 Subject: [PATCH] fix: extends types to `vue` instead of `@vue/runtime-core` (#638) --- src/core/declaration.ts | 6 ++---- test/__snapshots__/dts.test.ts.snap | 20 +++++--------------- test/dts.test.ts | 14 ++++---------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/core/declaration.ts b/src/core/declaration.ts index fec2886d..fa6241c4 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -118,11 +118,9 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?: ? `export {} declare module 'vue' {` - : `import '@vue/runtime-core' + : `export {} -export {} - -declare module '@vue/runtime-core' {` +declare module 'vue' {` let code = `/* eslint-disable */ /* prettier-ignore */ diff --git a/test/__snapshots__/dts.test.ts.snap b/test/__snapshots__/dts.test.ts.snap index 8f35d023..ea2af4da 100644 --- a/test/__snapshots__/dts.test.ts.snap +++ b/test/__snapshots__/dts.test.ts.snap @@ -6,11 +6,9 @@ exports[`dts > components only 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] @@ -26,11 +24,9 @@ exports[`dts > directive only 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface ComponentCustomProperties { vLoading: typeof import('test/directive/Loading')['default'] } @@ -44,11 +40,9 @@ exports[`dts > getDeclaration 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] @@ -122,11 +116,9 @@ exports[`dts > writeDeclaration - keep unused 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] @@ -148,11 +140,9 @@ exports[`dts > writeDeclaration 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] diff --git a/test/dts.test.ts b/test/dts.test.ts index 26c03a3c..b47de6b5 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -52,7 +52,7 @@ const _directive_loading = _resolveDirective("loading")` await writeFile( filepath, ` -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { SomeComp: typeof import('test/component/SomeComp')['default'] TestComp: typeof import('test/component/OldComp')['default'] @@ -128,11 +128,9 @@ const _directive_loading = _resolveDirective("loading")` // generated by unplugin-vue-components // We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { ComponentA: typeof import('./src/components/ComponentA.vue')['default'] ComponentB: typeof import('./src/components/ComponentB.vue')['default'] @@ -151,11 +149,9 @@ declare module '@vue/runtime-core' { // generated by unplugin-vue-components // We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { ComponentA: typeof import('./src/components/ComponentA.vue')['default'] 'IMdi:diceD12': typeof import('~icons/mdi/dice-d12')['default'] @@ -174,11 +170,9 @@ declare module '@vue/runtime-core' { // generated by unplugin-vue-components // We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core' - export {} -declare module '@vue/runtime-core' { +declare module 'vue' { export interface GlobalComponents { ComponentA: typeof import('./src/components/ComponentA.vue')['default'] 'IMdi:diceD12': typeof import('~icons/mdi/dice-d12')['default']