JamesBrill / react-speech-recognition

💬Speech recognition for your React app
https://webspeechrecognition.com/
MIT License
657 stars 119 forks source link

Add TypeScript support #51

Closed vahdet closed 4 years ago

vahdet commented 4 years ago

Firstly, thanks for the promising work! In my case, the basic import (import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition') fails the TypeScript check with code ts(7016):

Could not find a declaration file for module 'react-speech-recognition'. '.../my-proj/node_modules/react-speech-recognition/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-speech-recognition` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-speech-recognition';`

And npm install @types/react-speech-recognition throws:

Not Found - GET https://registry.npmjs.org/@types%2freact-speech-recognition - Not found

So, I had to workaround it with adding this in my app.d.ts file:

declare module 'react-speech-recognition';

So, do you have any agenda for adding TypeScript support? If needed, I also may contribute at my best effort.

JamesBrill commented 4 years ago

Hi @vahdet thanks for the suggestion. I have no experience with TypeScript (though it is of interest to me), so you may be better positioned to contribute a declaration file than me. If you make a PR for this, I can advise on the types and shape of the inputs/outputs.

You probably don't even need to do the whole thing - if you get it started and help me get an idea of how to structure and publish a declaration file, I can probably fill in the missing definitions.

vahdet commented 4 years ago

@JamesBrill Well, yesterday I tinkered with the code indeed. I forked the repo applied my work on a new branch feature/typecript-support. I have some experience with TypeScript, but cannot call myself a master of it. Anyways, I am sending a PR w/ my further explanation on what I've done; and then, improvements can be done on it (see: https://github.com/JamesBrill/react-speech-recognition/pull/52)

I won't be around for a couple of weeks, so I may react slower than today..

OleksandrYehorov commented 4 years ago

@vahdet @JamesBrill @types/react-speech-recognition is now available.

JamesBrill commented 4 years ago

Thank you @OleksandrYehorov - that is hugely appreciated. 🙇