withDefaults should work with an object literal reference
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)
We have to hoist defaultsObject
like this Vue Playground