|
| 1 | +import { Vue } from './vue' |
| 2 | +import { VNode } from './vnode' |
| 3 | +import { ComponentOptions as Vue2ComponentOptions } from './options' |
| 4 | +import { EmitsOptions, SetupContext } from './v3-setup-context' |
| 5 | +import { Data } from './common' |
| 6 | +import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props' |
| 7 | +import { ComponentRenderProxy } from './v3-component-proxy' |
| 8 | +export { ComponentPropsOptions } from './v3-component-props' |
| 9 | + |
| 10 | +export type ComputedGetter<T> = (ctx?: any) => T |
| 11 | +export type ComputedSetter<T> = (v: T) => void |
| 12 | + |
| 13 | +export interface WritableComputedOptions<T> { |
| 14 | + get: ComputedGetter<T> |
| 15 | + set: ComputedSetter<T> |
| 16 | +} |
| 17 | + |
| 18 | +export type ComputedOptions = Record< |
| 19 | + string, |
| 20 | + ComputedGetter<any> | WritableComputedOptions<any> |
| 21 | +> |
| 22 | + |
| 23 | +export interface MethodOptions { |
| 24 | + [key: string]: Function |
| 25 | +} |
| 26 | + |
| 27 | +export type SetupFunction< |
| 28 | + Props, |
| 29 | + RawBindings = {}, |
| 30 | + Emits extends EmitsOptions = {} |
| 31 | +> = ( |
| 32 | + this: void, |
| 33 | + props: Readonly<Props>, |
| 34 | + ctx: SetupContext<Emits> |
| 35 | +) => RawBindings | (() => VNode | null) | void |
| 36 | + |
| 37 | +interface ComponentOptionsBase< |
| 38 | + Props, |
| 39 | + D = Data, |
| 40 | + C extends ComputedOptions = {}, |
| 41 | + M extends MethodOptions = {} |
| 42 | +> extends Omit< |
| 43 | + Vue2ComponentOptions<Vue, D, M, C, Props>, |
| 44 | + 'data' | 'computed' | 'method' | 'setup' | 'props' |
| 45 | + > { |
| 46 | + // allow any custom options |
| 47 | + [key: string]: any |
| 48 | + |
| 49 | + // rewrite options api types |
| 50 | + data?: (this: Props & Vue, vm: Props) => D |
| 51 | + computed?: C |
| 52 | + methods?: M |
| 53 | +} |
| 54 | + |
| 55 | +export type ExtractComputedReturns<T extends any> = { |
| 56 | + [key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn } |
| 57 | + ? TReturn |
| 58 | + : T[key] extends (...args: any[]) => infer TReturn |
| 59 | + ? TReturn |
| 60 | + : never |
| 61 | +} |
| 62 | + |
| 63 | +export type ComponentOptionsWithProps< |
| 64 | + PropsOptions = ComponentPropsOptions, |
| 65 | + RawBindings = Data, |
| 66 | + D = Data, |
| 67 | + C extends ComputedOptions = {}, |
| 68 | + M extends MethodOptions = {}, |
| 69 | + Mixin = {}, |
| 70 | + Extends = {}, |
| 71 | + Emits extends EmitsOptions = {}, |
| 72 | + EmitsNames extends string = string, |
| 73 | + Props = ExtractPropTypes<PropsOptions> |
| 74 | +> = ComponentOptionsBase<Props, D, C, M> & { |
| 75 | + props?: PropsOptions |
| 76 | + emits?: (Emits | EmitsNames[]) & ThisType<void> |
| 77 | + setup?: SetupFunction<Props, RawBindings, Emits> |
| 78 | +} & ThisType< |
| 79 | + ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> |
| 80 | + > |
| 81 | + |
| 82 | +export type ComponentOptionsWithArrayProps< |
| 83 | + PropNames extends string = string, |
| 84 | + RawBindings = Data, |
| 85 | + D = Data, |
| 86 | + C extends ComputedOptions = {}, |
| 87 | + M extends MethodOptions = {}, |
| 88 | + Mixin = {}, |
| 89 | + Extends = {}, |
| 90 | + Emits extends EmitsOptions = {}, |
| 91 | + EmitsNames extends string = string, |
| 92 | + Props = Readonly<{ [key in PropNames]?: any }> |
| 93 | +> = ComponentOptionsBase<Props, D, C, M> & { |
| 94 | + props?: PropNames[] |
| 95 | + emits?: (Emits | EmitsNames[]) & ThisType<void> |
| 96 | + setup?: SetupFunction<Props, RawBindings, Emits> |
| 97 | +} & ThisType< |
| 98 | + ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> |
| 99 | + > |
| 100 | + |
| 101 | +export type ComponentOptionsWithoutProps< |
| 102 | + Props = {}, |
| 103 | + RawBindings = Data, |
| 104 | + D = Data, |
| 105 | + C extends ComputedOptions = {}, |
| 106 | + M extends MethodOptions = {}, |
| 107 | + Mixin = {}, |
| 108 | + Extends = {}, |
| 109 | + Emits extends EmitsOptions = {}, |
| 110 | + EmitsNames extends string = string |
| 111 | +> = ComponentOptionsBase<Props, D, C, M> & { |
| 112 | + props?: undefined |
| 113 | + emits?: (Emits | EmitsNames[]) & ThisType<void> |
| 114 | + setup?: SetupFunction<Props, RawBindings, Emits> |
| 115 | +} & ThisType< |
| 116 | + ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits> |
| 117 | + > |
| 118 | + |
| 119 | +export type WithLegacyAPI<T, D, C, M, Props> = T & |
| 120 | + Omit<Vue2ComponentOptions<Vue, D, M, C, Props>, keyof T> |
0 commit comments