亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.tsx 組件中的 .js 組件 - 沒有重載匹配此調用/屬性在類型 Intrinsic

.tsx 組件中的 .js 組件 - 沒有重載匹配此調用/屬性在類型 Intrinsic

DIEA 2021-12-23 16:20:51
我正在嘗試在 .tsx 函數組件的 render() 函數中包含一個 .jsx(或 .js)React 類有狀態組件。根據我嘗試的方法,我收到不同的錯誤“沒有屬性與此調用匹配”。我嘗試了在 github 上看到的東西,例如://...  /* tslint:disable */  const JSProfileDetails: any = ProfileDetails;   /* tslint:enable */  return (// ...   <JSProfileDetails        profileName={profileName}        profileDetails={profileDetails}        profileInitialValues={profileInitialValues}      />但實際上到目前為止沒有任何效果。我將該組件保存在 .jsx/.js 中,因為輸入它是相當不可能的。我在[email protected],我的tsconfig.json是:{  "compilerOptions": {    "baseUrl": ".",    "outDir": "build/dist",    "module": "esnext",    "target": "es6",    "lib": ["es2019", "dom"],    "sourceMap": true,    "allowJs": true,    "jsx": "react",    "moduleResolution": "node",    "rootDir": "src",    "forceConsistentCasingInFileNames": true,    "noImplicitReturns": true,    "noImplicitThis": true,    "noImplicitAny": false,    "importHelpers": true,    "strictNullChecks": false,    "suppressImplicitAnyIndexErrors": true,    "types": ["react", "node", "jest"],    "noUnusedLocals": true,    "skipLibCheck" : true,    "allowSyntheticDefaultImports": true  },  "exclude": [    "node_modules",    "build",    "scripts",    "acceptance-tests",    "webpack",    "jest",    "src/setupTests.ts"  ]}我得到的確切錯誤是:o overload matches this call.  Overload 1 of 2, '(props: TypographyProps, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)> | Component<...>', gave the following error.    Type 'string' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'.  Overload 2 of 2, '(props: PropsWithChildren<TypographyProps>, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<...>)> | Component<...>', gave the following error.    Type 'string' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'.
查看完整描述

2 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

我剛剛遇到了一個非常相似的問題。事實證明,我根據子組件上的屬性類型(或者可能是 TypeScript 的推斷?)調用了帶有無效屬性的 JSX 子組件。


const profile = someQuery.profile || {id: -1, name: "Guest"}

//...

<SubComponent profile={profile} />

id這里應該是一個字符串,而不是數字。談到-1為"-1"解決我的問題。


查看完整回答
反對 回復 2021-12-23
?
湖上湖

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}

      />

感謝您抽出寶貴時間提供意見。


查看完整回答
反對 回復 2021-12-23
  • 2 回答
  • 0 關注
  • 438 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號