From edaa6f6bc9736753574c049a919d4d9bc4b29b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 7 Jun 2022 13:44:57 +0800 Subject: [PATCH] fix: vue app typing (#8137) closes #8122 --- packages/constants/index.ts | 1 + packages/constants/key.ts | 1 + packages/element-plus/index.ts | 2 +- packages/element-plus/make-installer.ts | 9 +-------- tsconfig.web.json | 2 +- typings/env.d.ts | 5 +++++ 6 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 packages/constants/key.ts diff --git a/packages/constants/index.ts b/packages/constants/index.ts index 006cb51582fa9..b5fe6c845e1e8 100644 --- a/packages/constants/index.ts +++ b/packages/constants/index.ts @@ -1,4 +1,5 @@ export * from './aria' export * from './date' export * from './event' +export * from './key' export * from './size' diff --git a/packages/constants/key.ts b/packages/constants/key.ts new file mode 100644 index 0000000000000..7d912aa6f4133 --- /dev/null +++ b/packages/constants/key.ts @@ -0,0 +1 @@ +export const INSTALLED_KEY = Symbol('INSTALLED_KEY') diff --git a/packages/element-plus/index.ts b/packages/element-plus/index.ts index d73e8a00602e9..5ccd27ad618d1 100644 --- a/packages/element-plus/index.ts +++ b/packages/element-plus/index.ts @@ -4,7 +4,7 @@ export * from '@element-plus/constants' export * from '@element-plus/directives' export * from '@element-plus/hooks' export * from '@element-plus/tokens' -export { makeInstaller } from './make-installer' +export * from './make-installer' export const install = installer.install export const version = installer.version diff --git a/packages/element-plus/make-installer.ts b/packages/element-plus/make-installer.ts index 9ed06ea6a6ad2..71c105917649f 100644 --- a/packages/element-plus/make-installer.ts +++ b/packages/element-plus/make-installer.ts @@ -1,16 +1,9 @@ import { provideGlobalConfig } from '@element-plus/hooks' +import { INSTALLED_KEY } from '@element-plus/constants' import { version } from './version' import type { App, Plugin } from '@vue/runtime-core' import type { ConfigProviderContext } from '@element-plus/tokens' -const INSTALLED_KEY = Symbol('INSTALLED_KEY') - -declare module '@vue/runtime-core' { - interface App { - [INSTALLED_KEY]?: boolean - } -} - export const makeInstaller = (components: Plugin[] = []) => { const install = (app: App, options?: ConfigProviderContext) => { if (app[INSTALLED_KEY]) return diff --git a/tsconfig.web.json b/tsconfig.web.json index 055f5b13c4772..3792632c5c015 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -6,7 +6,7 @@ "lib": ["ES2018", "DOM", "DOM.Iterable"], "types": ["unplugin-vue-define-options"] }, - "include": ["packages", "typings/components.d.ts", "env.d.ts"], + "include": ["packages", "typings/components.d.ts", "typings/env.d.ts"], "exclude": [ "node_modules", "**/dist", diff --git a/typings/env.d.ts b/typings/env.d.ts index 713be73420e9b..799050318ba37 100644 --- a/typings/env.d.ts +++ b/typings/env.d.ts @@ -1,4 +1,5 @@ import type { vShow } from 'vue' +import type { INSTALLED_KEY } from '@element-plus/constants' declare global { const process: { @@ -16,6 +17,10 @@ declare global { } declare module '@vue/runtime-core' { + export interface App { + [INSTALLED_KEY]?: boolean + } + export interface GlobalComponents { Component: (props: { is: Component | string }) => void }