Working through trying to learn TypeScript and I have a quick question about destructing something. Say I have an object. I need to destruct prior to using the variables. For instance:
type artProps = {
articles: Article[],
loading: boolean
}
type Article = {
title: string,
author: string,
body: string,
date: number,
category: string,
_id: string
}
const [articles, loading] = data
How would I destructure data while declaring the type?
Using the standard : type
notation.
const foo:[number,string] = data;
const [articles, loading]:[number,string] = data;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With