2 回答

TA貢獻1942條經(jīng)驗 獲得超3個贊
這是因為Script是組件,但您的界面定義了它的props.
按照 lib源代碼,您可能必須執(zhí)行以下操作:
export interface ScriptProps {
url: string;
onLoad: () => void;
// etc...
}
export default class Script extends React.Component<ScriptProps> {}
評論后編輯
您的類型涉及第三方模塊。你必須向 Typescript 提出建議。為此,您將在模塊聲明中封裝您的類型,如下所示:
// index.d.ts
declare module 'react-load-script' {
// imports here...
export interface ScriptProps {
url: string;
onLoad: () => void;
// etc...
}
export default class Script extends React.Component<ScriptProps> {}
}

TA貢獻1813條經(jīng)驗 獲得超2個贊
注意:在項目的根目錄中創(chuàng)建一個名為“custom-types”的文件夾,并在其中創(chuàng)建文件“index.d.ts”
索引.d.ts
declare module 'your-module-that-has-no-types';
配置文件
{
"compilerOptions": {
// ...other props,
"typeRoots": ["./custom-types", "node_modules/@types"]
},
"include": [
"src"
, "custom-types/index.d.ts" ],
}
添加回答
舉報