获取组件的类型
获取组件的类型
- 第一种方式,通过
DefineComponent类型,传入自定义props泛型, - 注意:第二个参数和第三个参数,需要传一个空的对象。因为
DefineComponent类型有很多重载,不传的话,会匹配到其他any的重载,重而获取错的类型。 
export const FiledPropsDefine = {
  schema: {
    type: Object as PropType<Schema>,
    required: true,
  },
  value: {
    required: true,
  },
  onChange: {
    type: Function as PropType<(v: any) => void>,
    required: true,
  },
  rootSchema: {
    type: Object as PropType<Schema>,
    required: true,
  },
} as const
export type CommonFieldType = DefineComponent<
  typeof FiledPropsDefine,
  {},
  {}
>
- 第二种方式,可以导入组件,通过
typeof获取类型 
import SchemaItem from 'SchemaItem'
type ComponentType = typeof SchemaItem;
- 第三种方式,通过声明一个和组件传参一样的新的组件,再通过
typeof获取类型 
export const FiledPropsDefine = {
  schema: {
    type: Object as PropType<Schema>,
    required: true,
  },
  value: {
    required: true,
  },
  onChange: {
    type: Function as PropType<(v: any) => void>,
    required: true,
  },
  rootSchema: {
    type: Object as PropType<Schema>,
    required: true,
  },
} as const
export const TypeHelperComponent = defineComponent({
  props:  FiledPropsDefine,
},
})
export type ComponentType = typeof TypeHelperComponent