fix [api]: typing in modelWrapper
This commit is contained in:
parent
7c33864ae3
commit
05affca69d
1 changed files with 10 additions and 8 deletions
|
@ -4,19 +4,21 @@ export function useModel<Type>(
|
|||
propName = "modelValue",
|
||||
options: { type?: "object" | "array" } = {}
|
||||
) {
|
||||
const vm = getCurrentInstance().proxy
|
||||
const vm = getCurrentInstance()?.proxy
|
||||
if (!vm) throw "useModel is called without an instance"
|
||||
|
||||
let valueToSet
|
||||
if (options.type === "object") {
|
||||
valueToSet = (value: object) => {
|
||||
return { ...value }
|
||||
}
|
||||
} else if (options.type === "array") {
|
||||
let valueToSet: (arg0: Type) => Type
|
||||
|
||||
// @ts-expect-error strange typing
|
||||
if (options.type === "object") valueToSet = (value: object) => ({ ...value })
|
||||
else if (options.type === "array")
|
||||
// @ts-expect-error strange typing
|
||||
valueToSet = (value: unknown[]) => [...value]
|
||||
} else valueToSet = (value) => value
|
||||
else valueToSet = (value: Type) => value
|
||||
|
||||
return computed<Type>({
|
||||
get() {
|
||||
// @ts-expect-error strange typing
|
||||
return vm.$props[propName]
|
||||
},
|
||||
set(value) {
|
||||
|
|
Loading…
Add table
Reference in a new issue