DEV Community

Discussion on: Returning A Promise From A Function Is Extra Useful With TypeScript

Collapse
 
georgewl profile image
George WL • Edited

There's also the shorthand of

<WpApiPost[]>

instead of

<Array<WpApiPost>>
Collapse
 
shelob9 profile image
Josh Pollock • Edited

Good point. I like that it reads in order it unpacks:

// An array of WpApiPost
<Array<WpApiPost>>

// A promise that resolves to an array of WpApiPost objects.
<Promise<Array<WpApiPost>>>

But, shorter is generally better. 🤷‍♀️

Collapse
 
georgewl profile image
George WL

Nah, I think it's just preference really, neither is better

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt

If you have worked with DefinitelyTyped, which offers linting, you will find that bracketed favors Array, while otherwise favors [].