withDefaults() has type error when used default factory for type
Link to minimal reproduction
Steps to reproduce
Create component with
interface Props {
id?: string
}
withDefaults(defineProps<Props>(), {
id: () => Math.random().toString(36).slice(2)
})
What is expected?
Has no error
What is actually happening?
TS Show error
interface Props {
id?: string
}
withDefaults(defineProps<Props>(), {
id: () => Math.random().toString(36).slice(2) // Type '() => string' is not assignable to type 'string'
})
System Info
System:
OS: Windows 10 10.0.19044
CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
Memory: 3.15 GB / 15.42 GB
Binaries:
Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.47)
Internet Explorer: 11.0.19041.1566
Any additional comments?
In my script, I want to create a props that accepts a string or generates a random one. To generate a random string for each component, I need to use a factory for a primitive type. It works great in runtime but I encounter a type error