feat: add a default types in the $$Generic#2184
feat: add a default types in the $$Generic#2184fedorovvvv wants to merge 1 commit intosveltejs:masterfrom
Conversation
|
I fixed the condition, error output and ran all the tests. Everything's fine. I hope you will accept this PR or we will improve it together💛 |
|
No one has used this syntax yet because of the error condition, so the chance of affecting projects is minimal if not 0 |
|
We're currently leaning towards going with the generics attribute solution instead, which means <script generics="T extends number = 2">
interface $$Props {
value?:T
result?: T extends 2 ? 'AAAAAA' : 'OOOOO'
}
export let value:$$Props['value'] = 2
</script>Or using runes: <script generics="T extends number = 2">
let { value = 2, result } = $props<{
value?:T
result?: T extends 2 ? 'AAAAAA' : 'OOOOO'
}>();
</script> |
|
Whoa! Is Thanks💜 |
|
No official documentation yet, but it's described in the RFC |
|
Wow, these are absolute new solutions for types, thank you) I'm surprised I haven't seen this before |
Hi!✨
A common problem with $$Generic is that there was no way to set a default type
I tried to add more functionality and now it is possible to set the default type as the second argument to $$Generic
I think this will take types in svelte one step further and open up a lot of new possibilities
I can't live without default types))🥲