[英]Property Does not exist despite null coalescing and optional chaining
我有一段代碼,我在上面進行可選鏈接以及 null 合並。
我不明白為什么它仍然抱怨屬性不存在,如下圖所示
錯誤信息是
TS2339: Property 'drawer' does not exist on type '{}'.
export const AppBar = styled(BaseAppBar, {
shouldForwardProp: (prop) => prop !== "open",
})<AppBarProps>(({ theme }) => ({
zIndex: theme?.zIndex?.drawer ?? 2,
}));
AppBar.defaultProps = {
color: "primary",
};
錯誤提示'drawer' does not exist on type '{}'
,這意味着zIndex
的類型為空 object,您需要在theme
內全局定義zIndex
的類型或使用as
來進行類型斷言。
export const AppBar = styled(BaseAppBar, {
shouldForwardProp: (prop) => prop !== "open",
})<AppBarProps>(({ theme }) => ({
zIndex: (theme?.zIndex as { drawer: number }).drawer ?? 2,
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.