我想從 omdbapi 獲取電影資料。
我正在嘗試嵌入打字稿以確定我從端點獲得的確切資料(我是打字稿的新手)。
獲取到的資料的結構看起來是這樣的,如果是字串,是否真的需要在界面中單獨列出所有資料?
interface Movie {
Title: string;
Year: string;
Rated: string;
Released: string;
Runtime: string;
Genre: string;
Director: string;
Writer: string;
Actors: string;
Plot: string;
Language: string;
Country: string;
Awards: string;
Poster: string;
Ratings: [
{
Source: string;
Value: string;
},
{
Source: string;
Value: string;
},
{
Source: string;
Value: string;
}
];
Metascore: string;
imdbRating: string;
imdbVotes: string;
imdbID: string;
Type: string;
DVD: string;
BoxOffice: string;
Production: string;
Website: string;
Response: string;
}
uj5u.com熱心網友回復:
這聽起來像是一份作業Record:
type Movie = Record<"Title" | "Year" | "... more keys here ..." | "Website" | "Response", string> & {
Ratings: {
Source: string;
Value: string;
}[];
};
給它一個映射到字串的所有鍵的聯合,然后將記錄與保存型別為的物件型別相交(組合)Ratings。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/476045.html
