refactor(types): move component props interfaces + expose AllowedComponentProps

fix #1632
This commit is contained in:
Evan You 2020-07-19 14:09:37 -04:00
parent 2deb0c7a74
commit 03c681e396
4 changed files with 24 additions and 14 deletions

View File

@ -7,7 +7,12 @@ import {
ComponentOptionsMixin, ComponentOptionsMixin,
RenderFunction RenderFunction
} from './componentOptions' } from './componentOptions'
import { SetupContext, FunctionalComponent } from './component' import {
SetupContext,
FunctionalComponent,
AllowedComponentProps,
ComponentCustomProps
} from './component'
import { import {
CreateComponentPublicInstance, CreateComponentPublicInstance,
ComponentPublicInstanceConstructor ComponentPublicInstanceConstructor
@ -15,11 +20,7 @@ import {
import { ExtractPropTypes, ComponentPropsOptions } from './componentProps' import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
import { EmitsOptions } from './componentEmits' import { EmitsOptions } from './componentEmits'
import { isFunction } from '@vue/shared' import { isFunction } from '@vue/shared'
import { import { VNodeProps } from './vnode'
VNodeProps,
AllowedComponentProps,
ComponentCustomProps
} from './vnode'
// defineComponent is a utility that is primarily used for type inference // defineComponent is a utility that is primarily used for type inference
// when declaring components. Type inference is provided in the component // when declaring components. Type inference is provided in the component

View File

@ -53,6 +53,19 @@ import { componentAdded } from './devtools'
export type Data = Record<string, unknown> export type Data = Record<string, unknown>
/**
* For extending allowed non-declared props on components in TSX
*/
export interface ComponentCustomProps {}
/**
* Default allowed non-declared props on ocmponent in TSX
*/
export interface AllowedComponentProps {
class?: unknown
style?: unknown
}
// Note: can't mark this whole interface internal because some public interfaces // Note: can't mark this whole interface internal because some public interfaces
// extend it. // extend it.
export interface ComponentInternalOptions { export interface ComponentInternalOptions {

View File

@ -54,7 +54,7 @@ export { h } from './h'
// Advanced render function utilities // Advanced render function utilities
export { createVNode, cloneVNode, mergeProps, isVNode } from './vnode' export { createVNode, cloneVNode, mergeProps, isVNode } from './vnode'
// VNode types // VNode types
export { Fragment, Text, Comment, Static, ComponentCustomProps } from './vnode' export { Fragment, Text, Comment, Static } from './vnode'
// Built-in components // Built-in components
export { Teleport, TeleportProps } from './components/Teleport' export { Teleport, TeleportProps } from './components/Teleport'
export { Suspense, SuspenseProps } from './components/Suspense' export { Suspense, SuspenseProps } from './components/Suspense'
@ -159,7 +159,9 @@ export {
Component, Component,
FunctionalComponent, FunctionalComponent,
ComponentInternalInstance, ComponentInternalInstance,
SetupContext SetupContext,
ComponentCustomProps,
AllowedComponentProps
} from './component' } from './component'
export { export {
ComponentOptions, ComponentOptions,

View File

@ -71,12 +71,6 @@ export type VNodeHook =
| VNodeMountHook[] | VNodeMountHook[]
| VNodeUpdateHook[] | VNodeUpdateHook[]
export interface ComponentCustomProps {}
export interface AllowedComponentProps {
class?: unknown
style?: unknown
}
// https://github.com/microsoft/TypeScript/issues/33099 // https://github.com/microsoft/TypeScript/issues/33099
export type VNodeProps = { export type VNodeProps = {
key?: string | number key?: string | number