News for hackers. Stuff that matters.
Re:Comparing Svelte and React by Palmik on Wednesday March 24, 2021 @04:17PM (#26572341)
I use Svelte + TypeScript in my personal projects, what issues did you run into?
Re:Comparing Svelte and React by dhucerbin on Wednesday March 24, 2021 @04:40PM (#26572597)
Last I checked it was impossible to parametrize component type. In React you can write `<MenuSelect<User> users={...} />`.
Re:Comparing Svelte and React by Palmik on Friday March 26, 2021 @02:53AM (#26589437)
I am not sure I understand. In the `MenuSelect` component you can declare `export let users: Array<User>;` and then pass into `users` anything that has the `User` interface.
Re:Comparing Svelte and React by patwoz on Wednesday March 24, 2021 @04:45PM (#26572656)
Please don't. It looks awful. And I think it's not necessary. Typescript should inherit it's type depending on what you are passing into "users".
Re:Comparing Svelte and React by dhucerbin on Wednesday March 24, 2021 @06:11PM (#26573670)
I assume you don’t like invocation? That’s not the point here. In svelte you can’t* define type variable that’s bound to the same type in whole component. I can’t enforce that properties `items` is `T[]` and `selectedItem` is `T`.

* Last time I checked. I could be wrong now.

Re:Comparing Svelte and React by patwoz on Thursday March 25, 2021 @03:27AM (#26577337)
I'm writing about <MenuSelect<User users={..} /> and not about Svelte. I don't know anything about Svelte except what I just learned in the article. I just don't like the syntax of <MenuSelect<User> /> and favour <MenuSelect /> instead, because Typescript will inherit it's generic type from users={...}

See my example here: https://codesandbox.io/s/clever-neumann-89tnx?file=/src/App....

Re:Comparing Svelte and React by efrafa on Wednesday March 24, 2021 @05:42PM (#26573330)
There are valid reason to do that. Like a component that takes render function and item that is passed into it that can be anything.
Re:Comparing Svelte and React by patwoz on Thursday March 25, 2021 @03:27AM (#26577342)
You can do that, but you don't have to.

See my example here at line 26: https://codesandbox.io/s/clever-neumann-89tnx?file=/src/App....

Typescript will inherit the type automatically.

Re:Comparing Svelte and React by kecupochren on Thursday March 25, 2021 @05:49AM (#26578176)
That's amazing, thanks for the tip
Re:Comparing Svelte and React by pitaj on Wednesday March 24, 2021 @04:43PM (#26572629)
Lack of support for generics and explicitly typing Events/Props/Slots. There is an RFC but it's still a WIP: https://github.com/sveltejs/rfcs/pull/38