blueberryapps/react-load-script

TypeScript types definition

ovonkahle opened this issue ยท 4 comments

Using React with TypeScript (TSX) requires type definitions for node modules. Are there plans to release TypeScript definition (*.d.ts) for this module?

Would you accept a PR if I provide one to include the *.d.ts file in this project?

Get us out of the stone ages here!

sodle commented

Here's a quick and dirty set of typedefs. Enough to make VSCode stop screaming about missing types, at least.
https://gist.github.com/sodle/1173508af207a6bc277e8f3102f823de

An easy fix for a CRA project using @sodle's solution.
create a .d.ts file, then add typings below into it and restart your server.

declare interface IScriptProps {
  attributes?: object;
  onCreate?: () => void;
  onError?: () => void;
  onLoad: () => void;
  url: string;
}
declare class Script {
  props: IScriptProps;
  state: any;
  context: any;
  refs: any;
  forceUpdate(callback: any): void;
  render(): any;
  setState(partialState: any, callback: any): void;
}

declare module 'react-load-script' {
  export = Script;
}