Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I recently rewrote a small UI from Preact to Svelte and while it was certainly a learning experience, I have to say working with Svelte is fantastic.

My only complaint is that the Typescript support isn't quite perfect yet, but it's already very functional.



I use Svelte + TypeScript in my personal projects, what issues did you run into?


Last I checked it was impossible to parametrize component type. In React you can write `<MenuSelect<User> users={...} />`.


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.


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".


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.


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....


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.


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.


That's amazing, thanks for the tip


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: