Reputation: 1079
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?
Upvotes: 4
Views: 698
Reputation: 275849
Using the standard : type
notation.
const foo:[number,string] = data;
const [articles, loading]:[number,string] = data;
Upvotes: 2