Skip to content

Commit c0adb67

Browse files
committed
feat(types): expose ComponentCustomOptions for declaring custom options
1 parent be21cfb commit c0adb67

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

packages/runtime-core/src/componentOptions.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ import { Directive } from './directives'
5151
import { ComponentPublicInstance } from './componentProxy'
5252
import { warn } from './warning'
5353

54+
/**
55+
* Interface for declaring custom options.
56+
*
57+
* @example
58+
* ```ts
59+
* declare module '@vue/runtime-core' {
60+
* interface ComponentCustomOptions {
61+
* beforeRouteUpdate?(
62+
* to: Route,
63+
* from: Route,
64+
* next: () => void
65+
* ): void
66+
* }
67+
* }
68+
* ```
69+
*/
70+
export interface ComponentCustomOptions {}
71+
5472
export interface ComponentOptionsBase<
5573
Props,
5674
RawBindings,
@@ -59,7 +77,10 @@ export interface ComponentOptionsBase<
5977
M extends MethodOptions,
6078
E extends EmitsOptions,
6179
EE extends string = string
62-
> extends LegacyOptions<Props, D, C, M>, SFCInternalOptions {
80+
>
81+
extends LegacyOptions<Props, D, C, M>,
82+
SFCInternalOptions,
83+
ComponentCustomOptions {
6384
setup?: (
6485
this: void,
6586
props: Props,

packages/runtime-core/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ export {
189189
export {
190190
ComponentOptions,
191191
ComponentOptionsWithoutProps,
192-
ComponentOptionsWithObjectProps as ComponentOptionsWithProps,
193-
ComponentOptionsWithArrayProps
192+
ComponentOptionsWithObjectProps,
193+
ComponentOptionsWithArrayProps,
194+
ComponentCustomOptions
194195
} from './componentOptions'
195196
export {
196197
ComponentPublicInstance,

test-dts/componentCustomProperties.test-d.ts renamed to test-dts/componentTypeExtensions.test-d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import { expectError } from 'tsd'
1+
import { expectError, expectType } from 'tsd'
22
import { defineComponent } from './index'
33

44
declare module '@vue/runtime-core' {
5+
interface ComponentCustomOptions {
6+
test?(n: number): void
7+
}
8+
59
interface ComponentCustomProperties {
610
state: 'stopped' | 'running'
711
}
812
}
913

1014
export const Custom = defineComponent({
1115
data: () => ({ counter: 0 }),
16+
17+
test(n) {
18+
expectType<number>(n)
19+
},
20+
1221
methods: {
1322
aMethod() {
1423
expectError(this.notExisting)

0 commit comments

Comments
 (0)