-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Description
Describe the bug
useVModels mistakenly marks the returned ref object as possibly undefined if the respective property is optional.
This is not correct. The ref is always returned. The ref value is possibly undefined, but not the ref object itself.
Example:
const props = defineProps<{
foo: string;
bar?: string;
}>();
const emit = defineEmits<{
'update:foo': [foo: string];
'update:bar': [bar: string | undefined];
}>();
const { foo, bar } = useVModels(props, emit);
const bar2 = useVModel(props, 'bar', emit);
foo.value = 'foo'; // OK
bar.value = 'bar'; // 'bar' is possibly 'undefined' <------ Type error (but no runtime error)
bar2.value = 'bar2'; // OKHow to reproduce: in StackBlitz, run npm test.
Reproduction
https://stackblitz.com/edit/nuxt-starter-vj3utk?file=components%2Ftest.vue
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.18.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.4.2 - /usr/local/bin/npm
pnpm: 8.9.2 - /usr/local/bin/pnpm
npmPackages:
@vueuse/core: ^10.6.1 => 10.6.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
No labels