Skip to content

Commit e9fe51f

Browse files
pikaxcexbrayat
authored andcommitted
types(setProps): setProps to Partial props
1 parent eb4a23a commit e9fe51f

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/mount.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ export function mount<
5454
ComponentProps<C>,
5555
ComponentData<C> & ComponentExposed<C> & Omit<P, keyof ComponentProps<C>>
5656
>
57-
> & {
58-
LOOL: Exclude<P, ComponentProps<C>>
59-
}
57+
>
6058

6159
// implementation
6260
export function mount(

src/vueWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class VueWrapper<
244244
return nextTick()
245245
}
246246

247-
setProps(props: T['$props']): Promise<void> {
247+
setProps(props: Partial<T['$props']>): Promise<void> {
248248
// if this VM's parent is not the root or if setProps does not exist, error out
249249
if (this.vm.$parent !== this.rootVM || !this.__setProps) {
250250
throw Error('You can only use setProps on your mounted component')

test-dts/wrapper.d-test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,49 @@ expectType<{ [key: string]: any }>(wrapper.props())
120120
const ComponentWithProps = defineComponent({
121121
props: {
122122
foo: String,
123-
bar: Number,
124-
},
123+
bar: Number
124+
}
125125
})
126126

127-
const propsWrapper = mount(ComponentWithProps);
127+
const propsWrapper = mount(ComponentWithProps)
128128

129-
propsWrapper.setProps({foo: 'abc'})
130-
propsWrapper.setProps({foo: 'abc', bar: 123})
129+
propsWrapper.setProps({ foo: 'abc' })
130+
propsWrapper.setProps({ foo: 'abc', bar: 123 })
131131
// @ts-expect-error :: should require string
132-
propsWrapper.setProps({foo: 123})
132+
propsWrapper.setProps({ foo: 123 })
133133
// @ts-expect-error :: unknown prop
134-
propsWrapper.setProps({badProp: true})
134+
propsWrapper.setProps({ badProp: true })
135135

136136
expectType<string | undefined>(propsWrapper.props().foo)
137137
expectType<number | undefined>(propsWrapper.props().bar)
138138
// @ts-expect-error :: unknown prop
139-
propsWrapper.props().badProp;
139+
propsWrapper.props().badProp
140140

141141
expectType<string | undefined>(propsWrapper.props('foo'))
142142
expectType<number | undefined>(propsWrapper.props('bar'))
143143
// @ts-expect-error :: unknown prop
144144
propsWrapper.props('badProp')
145+
146+
const requiredPropsWrapper = mount(
147+
defineComponent({
148+
props: {
149+
foo: { type: String, required: true },
150+
bar: { type: Number, required: true }
151+
}
152+
}),
153+
{
154+
props: {
155+
foo: 'abc',
156+
bar: 123
157+
}
158+
}
159+
)
160+
161+
requiredPropsWrapper.setProps({
162+
foo: 'abc'
163+
})
164+
165+
requiredPropsWrapper.setProps({
166+
// @ts-expect-error wrong type
167+
foo: 1
168+
})

0 commit comments

Comments
 (0)