김일혁
김일혁

Reputation: 429

Is there any better way to IntrinsicAttributes & TYPE in Typescript

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 enter image description here

So, Is there any simple way to avoid this problem in typescript?

Upvotes: 0

Views: 85

Answers (1)

Bergi
Bergi

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

Related Questions