Skip to content

withDefaults should work with an object literal reference #8517

Open
@DiedeGu

Description

@DiedeGu

What problem does this feature solve?

Currently this does not work in my code:

const defaultsObject = {  name: "Evan You" }
// also: var defaultsObject = {  name: "Evan You" }
// also: let defaultsObject = {  name: "Evan You" }

const props = withDefaults(defineProps<{name: string}>(), defaultsObject)

This gives the following error: The 2nd argument of withDefaults must be an object literal.

There is a good change I am just doing something wrong, if not:

Since we can now use interfaces for the props it would be really nice to be able to pass an object to the defaults, it was also a suggestion on the topic The added value is having the defaults also shared through composables if they are the same in different components.

What does the proposed API look like?

import { inputPropertiesInterface, inputDefaultsObject } from '../common/Input';

const props = withDefaults(defineProps<inputPropertiesInterface>(), inputDefaultsObject)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions