react-load-script icon indicating copy to clipboard operation
react-load-script copied to clipboard

TypeScript types definition

Open ovonkahle opened this issue 7 years ago • 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?

ovonkahle avatar Feb 22 '18 21:02 ovonkahle

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

jberube avatar Mar 19 '18 19:03 jberube

Get us out of the stone ages here!

pbirsinger avatar Mar 05 '19 11:03 pbirsinger

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

sodle avatar May 27 '19 21:05 sodle

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;
}

emasys avatar Jan 23 '20 11:01 emasys