Skip to content

Commit 506a42a

Browse files
authored
types(runtime-core): added ComponentCustomProperties type to globalProperties (#5389)
1 parent 83f7e6f commit 506a42a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
MergedComponentOptions,
1212
RuntimeCompilerOptions
1313
} from './componentOptions'
14-
import { ComponentPublicInstance } from './componentPublicInstance'
14+
import {
15+
ComponentCustomProperties,
16+
ComponentPublicInstance
17+
} from './componentPublicInstance'
1518
import { Directive, validateDirectiveName } from './directives'
1619
import { RootRenderFunction } from './renderer'
1720
import { InjectionKey } from './apiInject'
@@ -70,7 +73,7 @@ export interface AppConfig {
7073

7174
performance: boolean
7275
optionMergeStrategies: Record<string, OptionMergeFunction>
73-
globalProperties: Record<string, any>
76+
globalProperties: ComponentCustomProperties & Record<string, any>
7477
errorHandler?: (
7578
err: unknown,
7679
instance: ComponentPublicInstance | null,

test-dts/componentTypeExtensions.test-d.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare module '@vue/runtime-core' {
66
}
77

88
interface ComponentCustomProperties {
9-
state: 'stopped' | 'running'
9+
state?: 'stopped' | 'running'
1010
}
1111

1212
interface ComponentCustomProps {
@@ -35,6 +35,14 @@ export const Custom = defineComponent({
3535
expectError(this.notExisting)
3636
this.counter++
3737
this.state = 'running'
38+
39+
this.$.appContext.config.globalProperties.state = 'running'
40+
41+
expectError(
42+
// @ts-expect-error
43+
(this.$.appContext.config.globalProperties.state = 'not valid')
44+
)
45+
3846
// @ts-expect-error
3947
expectError((this.state = 'not valid'))
4048
}

0 commit comments

Comments
 (0)