Reputation: 429
This code is works good.
<AuctionCardGenerator auction={auction} />;
interface auctionType {
auction: randomAuctionType;
}
const AuctionCardGenerator = ({ auction }: auctionType) => {
...
}
and randomAuctionType is looks this.
interface randomAuctionType {
id: number;
title: string;
artist: {
id: number;
name: string;
nickname: string;
};
type: string;
price: string;
description: string;
status: AUCTION_STATE;
nftToken?: string;
imgSrc: string;
}
But I think that declaring auctionType just for this code isn't efficient. So I want to use just like bellow.
const AuctionCardGenerator = (auction: randomAuctionType) => {
But this code has error message like this
So, Is there any simple way to avoid this problem in typescript?
Upvotes: 0
Views: 85
Reputation: 664767
If you don't want to declare a standalone interface
(although there's nothing wrong with it - it doesn't cost you anything!), you can use an inline type literal instead:
const AuctionCardGenerator = ({ auction }: { auction: randomAuctionType; }) => {
...
}
Upvotes: 1