Skip to content

Commit

Permalink
types(runtime-core): added ComponentCustomProperties type to `globa…
Browse files Browse the repository at this point in the history
…lProperties` (#5389)
  • Loading branch information
nandi95 authored Oct 26, 2022
1 parent 83f7e6f commit 506a42a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion test-dts/componentTypeExtensions.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare module '@vue/runtime-core' {
}

interface ComponentCustomProperties {
state: 'stopped' | 'running'
state?: 'stopped' | 'running'
}

interface ComponentCustomProps {
Expand Down Expand Up @@ -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'))
}
Expand Down

0 comments on commit 506a42a

Please sign in to comment.