我有這個模型:
export interface SizeAndColors {
size: string;
color: string;
}[];
然后我有另一個模型,我需要 sizeAndColor 但沒有陣列。
export interface Cart {
options: SizeAndColors
}
我怎么能在選項中說我想在沒有陣列的情況下擁有這個界面?那可能嗎 ?
uj5u.com熱心網友回復:
假設SizeAndColors確實被宣告為陣列型別,其中元素是具有size和color屬性的物件(問題中的內容[似乎不是] [1]),我建議拆分原始介面:
interface SizeAndColorsElement {
size: string;
colors: string;
}
export type SizeAndColors = SizeAndColorsElement[];
但如果你不能,你可以使用它SizeAndColors[number]來訪問其中的物件部分:
export interface Cart {
options: SizeAndColors[number];
}
再說一遍:假設它真的被定義為一個陣列型別,它似乎不在問題的代碼中。
uj5u.com熱心網友回復:
像這樣定義你的界面
export interface SizeAndColors {
size: string;
color: string;
}
并僅在需要時使用陣列
export interface Cart {
options: SizeAndColors[]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/469251.html
標籤:javascript 反应 打字稿 反应式
上一篇:使用成功回呼中狀態的初始值反應NativeGeoLocation.watchPosition()
下一篇:React-nativespotifyapi呼叫回傳[未處理的承諾拒絕:TypeError:未定義不是物件(評估'data.items.name.map')]
