types: ensure props are readonly
This commit is contained in:
@@ -14,7 +14,10 @@ import { VNodeProps } from './vnode'
|
||||
// overload 1: direct setup function
|
||||
// (uses user defined props interface)
|
||||
export function createComponent<Props, RawBindings = object>(
|
||||
setup: (props: Props, ctx: SetupContext) => RawBindings | RenderFunction
|
||||
setup: (
|
||||
props: Readonly<Props>,
|
||||
ctx: SetupContext
|
||||
) => RawBindings | RenderFunction
|
||||
): {
|
||||
new (): ComponentPublicInstance<
|
||||
Props,
|
||||
|
||||
@@ -83,7 +83,7 @@ export type ComponentOptionsWithoutProps<
|
||||
M extends MethodOptions = {}
|
||||
> = ComponentOptionsBase<Props, RawBindings, D, C, M> & {
|
||||
props?: undefined
|
||||
} & ThisType<ComponentPublicInstance<{}, RawBindings, D, C, M, Props>>
|
||||
} & ThisType<ComponentPublicInstance<{}, RawBindings, D, C, M, Readonly<Props>>>
|
||||
|
||||
export type ComponentOptionsWithArrayProps<
|
||||
PropNames extends string = string,
|
||||
@@ -91,7 +91,7 @@ export type ComponentOptionsWithArrayProps<
|
||||
D = {},
|
||||
C extends ComputedOptions = {},
|
||||
M extends MethodOptions = {},
|
||||
Props = { [key in PropNames]?: any }
|
||||
Props = Readonly<{ [key in PropNames]?: any }>
|
||||
> = ComponentOptionsBase<Props, RawBindings, D, C, M> & {
|
||||
props: PropNames[]
|
||||
} & ThisType<ComponentPublicInstance<Props, RawBindings, D, C, M>>
|
||||
@@ -102,7 +102,7 @@ export type ComponentOptionsWithObjectProps<
|
||||
D = {},
|
||||
C extends ComputedOptions = {},
|
||||
M extends MethodOptions = {},
|
||||
Props = ExtractPropTypes<PropsOptions>
|
||||
Props = Readonly<ExtractPropTypes<PropsOptions>>
|
||||
> = ComponentOptionsBase<Props, RawBindings, D, C, M> & {
|
||||
props: PropsOptions
|
||||
} & ThisType<ComponentPublicInstance<Props, RawBindings, D, C, M>>
|
||||
|
||||
@@ -65,14 +65,8 @@ export type ExtractPropTypes<
|
||||
O,
|
||||
MakeDefaultRequired extends boolean = true
|
||||
> = O extends object
|
||||
? {
|
||||
readonly [K in RequiredKeys<O, MakeDefaultRequired>]: InferPropType<O[K]>
|
||||
} &
|
||||
{
|
||||
readonly [K in OptionalKeys<O, MakeDefaultRequired>]?: InferPropType<
|
||||
O[K]
|
||||
>
|
||||
}
|
||||
? { [K in RequiredKeys<O, MakeDefaultRequired>]: InferPropType<O[K]> } &
|
||||
{ [K in OptionalKeys<O, MakeDefaultRequired>]?: InferPropType<O[K]> }
|
||||
: { [K in string]: any }
|
||||
|
||||
const enum BooleanFlags {
|
||||
|
||||
Reference in New Issue
Block a user