-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type () => boolean
is not assignable type boolean
when using withDefault
with a factory function
#7677
Comments
() => boolean
is not assignable type boolean
() => boolean
is not assignable type boolean
when using withDefault
with a factory function
If I add a
|
@LinusBorg @yyx990803 How are pending PR reviewed/managed ? Any chance that this will get merged with 3.3 ? |
@LinusBorg @yyx990803 |
EDIT: I just realized that the withDefaults macro is documents to remove undefined from the defaulted props; however, in my use case the function used for the default value can return a value OR undefined, depending on circumstances, where undefined is a perfectly valid value meaning "unused". Perhaps withDefaults is just not appropriate for this use case? Original comment follows: I don't know if this is related, but if a prop is optional, returning undefined from a function also triggers a type error, even though doing the same in the options API is fine (and the only way to positively assign undefined as the default value). e.g., given: interface Props {
opt?: string
} Then: const props: Props = defineProps({
opt: String,
required: false,
default: () => undefined
}) works fine, but: const props = withDefaults(defineProps<Props>(), {
opt: () => undefined
}) causes a type error:
|
@nborko Well, in your first exemple the
|
Closing this issue since it's working on the latest version, playground |
Vue version
3.2.47
Link to minimal reproduction
.
Steps to reproduce
Not sure why there is a type error on
hwAcceleration
but notduration
if it's invalid.Changing the interface to this solve the type error, but it seems wrong.
The type of the value is still
boolean
, the fact that Vue need a factory function inwithDefaults
doesn't change the nature of the value, is this a bug withwithDefaults
?What is expected?
It shouldn't be required from the Vue documentation.
Reference: https://vuejs.org/api/sfc-script-setup.html#default-props-values-when-using-type-declaration.
What is actually happening?
System Info
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: