Skip to content

Commit 03c681e

Browse files
committed
refactor(types): move component props interfaces + expose AllowedComponentProps
fix #1632
1 parent 2deb0c7 commit 03c681e

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

packages/runtime-core/src/apiDefineComponent.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import {
77
ComponentOptionsMixin,
88
RenderFunction
99
} from './componentOptions'
10-
import { SetupContext, FunctionalComponent } from './component'
10+
import {
11+
SetupContext,
12+
FunctionalComponent,
13+
AllowedComponentProps,
14+
ComponentCustomProps
15+
} from './component'
1116
import {
1217
CreateComponentPublicInstance,
1318
ComponentPublicInstanceConstructor
1419
} from './componentProxy'
1520
import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
1621
import { EmitsOptions } from './componentEmits'
1722
import { isFunction } from '@vue/shared'
18-
import {
19-
VNodeProps,
20-
AllowedComponentProps,
21-
ComponentCustomProps
22-
} from './vnode'
23+
import { VNodeProps } from './vnode'
2324

2425
// defineComponent is a utility that is primarily used for type inference
2526
// when declaring components. Type inference is provided in the component

packages/runtime-core/src/component.ts

+13
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ import { componentAdded } from './devtools'
5353

5454
export type Data = Record<string, unknown>
5555

56+
/**
57+
* For extending allowed non-declared props on components in TSX
58+
*/
59+
export interface ComponentCustomProps {}
60+
61+
/**
62+
* Default allowed non-declared props on ocmponent in TSX
63+
*/
64+
export interface AllowedComponentProps {
65+
class?: unknown
66+
style?: unknown
67+
}
68+
5669
// Note: can't mark this whole interface internal because some public interfaces
5770
// extend it.
5871
export interface ComponentInternalOptions {

packages/runtime-core/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export { h } from './h'
5454
// Advanced render function utilities
5555
export { createVNode, cloneVNode, mergeProps, isVNode } from './vnode'
5656
// VNode types
57-
export { Fragment, Text, Comment, Static, ComponentCustomProps } from './vnode'
57+
export { Fragment, Text, Comment, Static } from './vnode'
5858
// Built-in components
5959
export { Teleport, TeleportProps } from './components/Teleport'
6060
export { Suspense, SuspenseProps } from './components/Suspense'
@@ -159,7 +159,9 @@ export {
159159
Component,
160160
FunctionalComponent,
161161
ComponentInternalInstance,
162-
SetupContext
162+
SetupContext,
163+
ComponentCustomProps,
164+
AllowedComponentProps
163165
} from './component'
164166
export {
165167
ComponentOptions,

packages/runtime-core/src/vnode.ts

-6
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ export type VNodeHook =
7171
| VNodeMountHook[]
7272
| VNodeUpdateHook[]
7373

74-
export interface ComponentCustomProps {}
75-
export interface AllowedComponentProps {
76-
class?: unknown
77-
style?: unknown
78-
}
79-
8074
// https://github.com/microsoft/TypeScript/issues/33099
8175
export type VNodeProps = {
8276
key?: string | number

0 commit comments

Comments
 (0)