interfaceProps{id?: string}withDefaults(defineProps<Props>(),{id: ()=>Math.random().toString(36).slice(2)// Type '() => string' is not assignable to type 'string'})
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
The text was updated successfully, but these errors were encountered:
Link to minimal reproduction
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAXAngBwQOQPaIKoDtQAzAS3xGAB4AVAPngF55r4QAPREQgZ3gFdCIUuWDwA-PHIA3EDHgAuZgG4AsACh160JFgIU6eAEl8RWQBEhUPhESUACgBpm9Ji3acek6xHgAfLwC2AEayfvDciDBkAOZhQVhYECBQ+GHcyMGJYQBiAmCIJFipEiyKABSoMFio3Ip2AJSM9NSqGmra0HBIaAjGpjAWRFY23DQu8ADe6vAz8ADaANLwZPAA1iDIWETMALpiin3mlta21E7YeILCFDSLO7S0rQC+rVrgnXo98HZVNQDqJEQAAtBsNEKMAEJQbggJygk7ccZQmHwABkk2ms0Wy1S60223hIx2iiW7i4wF4eK28GRCAkFwIxDIN1pd3oimksmer3a7108CIeQKRXgAHdASDjiN7L9uHCpeDWBxybxDgMFaMftVEbQKrK6rKnMQwbV4ITwfUDdqAcDzZrDWaNY9NGp2KgsDBEPAOvzBfh8oVUkzyFqajQeqHEWVLfAAErJYBFCDIcPoSPOtougD0WfgAGEsAF3eR8IgAHRSPggF1kTgwIZgBCRjFqGYkYD7cKRGLqJ6Y9Ti20asrBkCRmXa3X1JxTVvLYDlRoMegAWSgwLLMBSiYC0bLiCwAGVu-homUAMwANnqZe4EBIjbKACZ6r36kA
Steps to reproduce
Create component with
What is expected?
Has no error
What is actually happening?
TS Show error
System Info
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
The text was updated successfully, but these errors were encountered: