ui
ui copied to clipboard
Unable to use boolean values with USelectMenu or null with UInput
Environment
- Operating System: Windows_NT
- Node Version: v20.12.2
- Nuxt Version: 3.10.3
- CLI Version: 3.10.1
- Nitro Version: 2.9.1
- Package Manager: [email protected]
- Builder: -
- User Config: app, colorMode, ui, css, modules, runtimeConfig, authJs, pinia, nitro, alias, devtools, imports, typescript
- Runtime Modules: @pinia/[email protected], @pinia-plugin-persistedstate/[email protected], @vueuse/[email protected], @hebilicious/[email protected], @nuxtjs/[email protected], [email protected], [email protected], @nuxt/[email protected]
- Build Modules: -
Version
v2.14.2
Reproduction
https://stackblitz.com/edit/nuxt-ui-eqhn2j?file=app.vue
Description
I'm getting multiple new type errors that I wasn't getting before with types that used to be valid. I think this is being caused by an update to vue-tsc, however I'm not sure.
In the reproduction link you can see the two examples that don't compile. Simply run npm run typecheck in the console to get the errors
Here are the minimal examples
<script setup lang="ts">
const value = ref<string | null | undefined>(undefined);
</script>
<template>
<div>
<UInput v-model.trim="value" />
</div>
</template>
TS2322: Type 'string | null | undefined' is not assignable to type 'string | number | undefined'.
<script setup lang="ts">
const value = ref<boolean|undefined>();
const options = [
{
label: 'Yes',
value: true
},
{
label: 'No',
value: false
},
{
label: 'None selected',
value: undefined
}
];
</script>
<template>
<div>
<USelectMenu
:options="options"
v-model="value"
value-attribute="value" option-attribute="label"
/>
</div>
</template>
TS2322: Type 'boolean | undefined' is not assignable to type 'string | number | Record<string, any> | unknown[] | undefined'.
Additional context
Logs
app.vue:14:15 - error TS2322: Type 'string | null | undefined' is not assignable to type 'string | number | undefined'.
14 <UInput v-model.trim="inputValue" />
~~~~~~~~~~
node_modules/@nuxt/ui/dist/runtime/components/forms/Input.vue.d.ts:244:5
244 modelValue: string | number;
~~~~~~~~~~
The expected type comes from property 'modelValue' which is declared here on type 'Partial<{ size: InputSize; ui: any; id: string; icon: string; color: any; type: string; class: any; name: string; modelValue: string | number; leading: boolean; variant: InputVariant; ... 12 more ...; modelModifiers: { ...; }; }> & Omit<...> & Record<...>'
Found 1 error in app.vue:14
I've also tried downgrading vue-tsc to the latest ^1.8.27 release according to the warning in https://nuxt.com/docs/guide/concepts/typescript but I still get the error. I've updated the stackblitz with the downgraded version
I have the same issue with UInput, it should accept null as v-model value
I also can't use Booleans in Select
Any update?
@nuxt