-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Open
Labels
has workaroundA workaround has been found to avoid the problemA workaround has been found to avoid the problemscope: sfc
Description
Vue version
3.5.19
Link to minimal reproduction
Steps to reproduce
Our specific issue is that when using generic components for defining props, the runtime prop type is missing and therefore the Boolean Casting doesn't work as expected.
- Define a generic component
<script lang="ts" setup generic="TMultiple extends boolean">
type Nullable<T> = T | null | undefined;
type Props<TMultiple extends boolean> = {
primitive: boolean;
wrapped: Nullable<boolean>;
multiple: TMultiple;
checked: TMultiple extends true ? boolean : never;
}
const props = defineProps<Props<TMultiple>>();
</script>
<template>
<div>
{{ $props }}
</div>
</template>
- Use the boolean props
<template>
<Comp primitive wrapped multiple checked />
</template>
- The resulting output for
$props
is:
{ "multiple": "", "checked": "", "primitive": true, "wrapped": true }
- The compiled runtime output is:
Note that the runtime prop types for multiple
and checked
are missing
const __sfc__ = /*@__PURE__*/_defineComponent({
__name: 'Comp',
props: {
primitive: { type: Boolean },
wrapped: { type: [Boolean, null] },
multiple: {},
checked: {}
},
setup(__props) {
const props = __props;
return (_ctx,_cache) => {
return (_openBlock(), _createElementBlock("div", null, _toDisplayString(_ctx.$props), 1 /* TEXT */))
}
}
})
What is expected?
- boolean casting should also work for the
multiple
andchecked
properties sotrue
is passed as value - runtime prop types for
multiple
andchecked
are inferred correctly
What is actually happening?
- runtime prop types for
multiple
andchecked
are missing multiple
andchecked
booleans are passed as empty strings instead oftrue
boolean
System Info
System:
OS: macOS 15.6
CPU: (14) arm64 Apple M4 Max
Memory: 394.27 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.15.0 - ~/.local/state/fnm_multishells/32954_1755762140665/bin/node
npm: 10.9.2 - ~/.local/state/fnm_multishells/32954_1755762140665/bin/npm
pnpm: 10.14.0 - /opt/homebrew/bin/pnpm
bun: 1.2.20 - /opt/homebrew/bin/bun
Browsers:
Chrome: 139.0.7258.128
Edge: 139.0.3405.102
Safari: 18.6
npmPackages:
vue: ^3.5.19 => 3.5.19
Any additional comments?
In #12876 / #12872 the issue was fixed that boolean casting does not work when using wrapped generics (e.g. Nullable<boolean>
as property type). The issue was fixed with version 3.5.19.
However, the issue still exists when using generic components as described above.
An example use case for this is a select / dropdown component that can either be single or multiselect that uses a generic TMultiple
type for typing the modelValue property either as single value or as array.
Metadata
Metadata
Assignees
Labels
has workaroundA workaround has been found to avoid the problemA workaround has been found to avoid the problemscope: sfc