[K in keyof P]: PropValidator<P[K]>
}
-export type NormalizedPropsOptions<P = Data> = {
- [K in keyof P]: PropOptions<P[K]>
-}
-
export type Prop<T> = { (): T } | { new (...args: any[]): T & object }
export type PropType<T> = Prop<T> | Prop<T>[]
import {
Data,
ComponentPropsOptions,
- NormalizedPropsOptions,
PropValidator,
PropOptions
} from './componentOptions'
Component: ComponentClass | FunctionalComponent
): { props: Data; attrs?: Data } {
const hasDeclaredProps = rawOptions !== void 0
- const options = (hasDeclaredProps &&
- normalizePropsOptions(
- rawOptions as ComponentPropsOptions
- )) as NormalizedPropsOptions
+ const options = rawOptions as ComponentPropsOptions
if (!rawData && !hasDeclaredProps) {
return EMPTY_PROPS
}
if (props[key] === void 0) {
const opt = options[key]
if (opt != null && opt.hasOwnProperty('default')) {
- const defaultValue = opt.default
+ const defaultValue = (opt as PropOptions).default
props[key] =
typeof defaultValue === 'function' ? defaultValue() : defaultValue
}
return { props, attrs }
}
-const normalizeCache = new WeakMap<
- ComponentPropsOptions,
- NormalizedPropsOptions
->()
-
-function normalizePropsOptions(
- raw: ComponentPropsOptions
-): NormalizedPropsOptions {
- let cached = normalizeCache.get(raw)
- if (cached) {
- return cached
- }
- const normalized: NormalizedPropsOptions = {}
- for (const key in raw) {
- const opt = raw[key]
- normalized[key] =
- typeof opt === 'function' ? { type: opt } : (opt as PropOptions)
- }
- normalizeCache.set(raw, normalized)
- return normalized
-}
-
function validateProp(
key: string,
value: any,