It seems obfuscated. Why not declare the Item separately? type Item = { id: number, name: string} type Items = Array<Item>
-
-
-
If you're in control of all the types you're right and that's clearly the way to go. The lookup example I gave is still needed e.g. if you're using a library that doesn't expose the "Item" type directly. You'd be left with rewriting the structure by hand.
- Još 1 odgovor
Novi razgovor -
-
-
- Kraj razgovora
Novi razgovor -
-
-
Note that that works for any property, so you can do things like `type nameType = Items[0]['name'] // string ` etc etc
-
Good point! I actually got inspired by this
@SeaRyanC's post: https://twitter.com/SeaRyanC/status/1214665688679206913 … (This thread could also provide some answers for your question,@danbruegge) - Još 1 odgovor
Novi razgovor -
-
-
Interesting :) I typically use a more universal tool for that: conditional + infer I mentioned that recently in my talk as well: https://youtu.be/T-vQoI_AM9E?t=870 …pic.twitter.com/JCAkRWmkZ4
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Indeed. Checkout this patternhttps://twitter.com/styfle/status/1208787362613989381 …
0:23Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Yeah found this not so long ago. Have same aha moment - it so simple and logical. That's what like about TS have few constructs but you can do a lot of powerful stuff.
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Please, can you explain how this is working? Why number? Is the number related to the Item type? Will it also work if i you use the string?
-
Using number(index) you could get access to array elements
- Još 1 odgovor
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
· writes about
)
So,