I am struggling to add a type declaration for react-load-script within a Create React App application.
Within the src folder, I created a react-load-script.d.ts file and added the following:
// Type definitions for React Load Script
declare module 'react-load-script' {
import * as React from 'react'
interface Script {
url: string
}
}
With the above I am getting the error:
JSX element type 'Script' does not have any construct or call signatures.
Where am I going wrong? This is the module: https://github.com/blueberryapps/react-load-script
This is my current use of it within the app:
<Script url="https://maps.googleapis.com/maps/api/js? key=your_api_key&libraries=places"
/>
I also need to add types for the onLoad:
<Script url="https://maps.googleapis.com/maps/api/js? key=your_api_key&libraries=places"
onLoad={this.handleScriptLoad}
/>
Thanks so much.
Update from comments
I moved and renamed the declaration file to /@types/react-load-script/index.d.ts
In tsconfig.json I added the following to compilerOptions:
"typeRoots": ["./node_modules/@types", "./@types"]
This is the index.d.ts entire contents:
// Type definitions for React Load Script
import React from 'react'
export interface ScriptProps {
url: string
onLoad: () => void
// etc...
}
export default class Script extends React.Component<ScriptProps> {}
With this I am still getting the error:
Could not find a declaration file for module 'react-load-script'. '/Users/sb/git/fl-app/node_modules/react-load-script/lib/index.js' implicitly has an 'any' type.