Hacker News new | past | comments | ask | show | jobs | submit login

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




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: