]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-core): added `ComponentCustomProperties` type to `globalProperties...
authornandi95 <41805560+nandi95@users.noreply.github.com>
Wed, 26 Oct 2022 09:00:47 +0000 (10:00 +0100)
committerGitHub <noreply@github.com>
Wed, 26 Oct 2022 09:00:47 +0000 (05:00 -0400)
packages/runtime-core/src/apiCreateApp.ts
test-dts/componentTypeExtensions.test-d.tsx

index dbf71951b16bf5d8e83abbc072e8052276fbcb4f..1c588dbc8f86fca5bb811c1e85f90706574629de 100644 (file)
@@ -11,7 +11,10 @@ import {
   MergedComponentOptions,
   RuntimeCompilerOptions
 } from './componentOptions'
-import { ComponentPublicInstance } from './componentPublicInstance'
+import {
+  ComponentCustomProperties,
+  ComponentPublicInstance
+} from './componentPublicInstance'
 import { Directive, validateDirectiveName } from './directives'
 import { RootRenderFunction } from './renderer'
 import { InjectionKey } from './apiInject'
@@ -70,7 +73,7 @@ export interface AppConfig {
 
   performance: boolean
   optionMergeStrategies: Record<string, OptionMergeFunction>
-  globalProperties: Record<string, any>
+  globalProperties: ComponentCustomProperties & Record<string, any>
   errorHandler?: (
     err: unknown,
     instance: ComponentPublicInstance | null,
index 3ff5b7addb0d213c484b75afa916e80a3d2bfe70..e26c272c70307685c39007bb9de84af2fb6a10fb 100644 (file)
@@ -6,7 +6,7 @@ declare module '@vue/runtime-core' {
   }
 
   interface ComponentCustomProperties {
-    state: 'stopped' | 'running'
+    state?: 'stopped' | 'running'
   }
 
   interface ComponentCustomProps {
@@ -35,6 +35,14 @@ export const Custom = defineComponent({
       expectError(this.notExisting)
       this.counter++
       this.state = 'running'
+
+      this.$.appContext.config.globalProperties.state = 'running'
+
+      expectError(
+        // @ts-expect-error
+        (this.$.appContext.config.globalProperties.state = 'not valid')
+      )
+
       // @ts-expect-error
       expectError((this.state = 'not valid'))
     }