Issue
export interface BookProps {
link: string;
title: string;
image: string;
author: string;
discount: string;
publisher: string;
description: string;
}
Is there a way to express that all elements in the interface have a string type in a concise manner?
Solution
You could use index properties to achieve a general interface definition.
interface Book {
[prop: string]: string;
}
const nineteenEightyFour: Book = {
link: "https://...",
title: "nineteenEightyFour",
....
}
Ts should be happy enough with this.
Answered By - monkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.