2 回答

TA貢獻1869條經驗 獲得超4個贊
我剛剛遇到了一個非常相似的問題。事實證明,我根據子組件上的屬性類型(或者可能是 TypeScript 的推斷?)調用了帶有無效屬性的 JSX 子組件。
const profile = someQuery.profile || {id: -1, name: "Guest"}
//...
<SubComponent profile={profile} />
id這里應該是一個字符串,而不是數字。談到-1為"-1"解決我的問題。

TA貢獻2003條經驗 獲得超2個贊
結果證明這是兩個問題的組合:
首先,錯誤Type 'string' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'指的是一個完全不同的組件,一個正在使用material-ui Typography組件的組件,這里已經提出并回答了一個問題:Typography component。當我添加這張票時,我在嘗試一些事情的同時升級了我的依賴項,material-ui然后新版本拋出了這個新錯誤。
其次,在組件內Property 'profileName' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Pick<RouteComponentProps<any, StaticContext, any>, never>, any, any>> & Readonly<Pick<RouteComponentProps<any, StaticContext, any>, never>> & Readonly<...>'. 渲染.js組件時出現的錯誤.tsx確實使用我已經包含在我的問題中的語法被消除了:
/* tslint:disable */
const JSProfileDetails: any = ProfileDetails;
/* tslint:enable */
return (
<JSProfileDetails
profileName={profileName}
profileDetails={profileDetails}
profileInitialValues={profileInitialValues}
/>
感謝您抽出寶貴時間提供意見。
添加回答
舉報