hackingbeauty / react-mic

Record audio from a user's microphone and display a cool visualization.
https://hackingbeauty.github.io/react-mic/
452 stars 158 forks source link

Add TypeScript types #81

Closed mikaello closed 4 years ago

mikaello commented 4 years ago

It would be nice if this module could have associated TypeScript-types in DefinitelyTyped. Info on how to create such a type package is documented in their repo.

Here is what I have created so far, if someone wants to build off this:

declare module 'react-mic' {
  import * as React from 'react';

  export default class ReactMic extends React.PureComponent<ReactMicProps> {}

  export interface ReactMicProps {
    /** Set to true to begin recording */
    record?: boolean;

    /** Available in React-Mic-Plus upgrade only */
    pause?: boolean;

    visualSetting?: 'sinewave' | 'frequencyBars';

    className?: string;

    /** Callback that is executed when audio stops recording */
    onStop?: (recordedData: Blob) => void;

    /** Callback that is executed when chunk of audio is available */
    onData?: (recordedData: Blob) => void;

    /** Sound wave color */
    strokeColor?: string;

    /** Background color */
    backgroundColor?: string;
  }
}
mikaello commented 4 years ago

Added pull-request to DefinitelyTyped now: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40845

mikaello commented 4 years ago

It is now merged into DefinitelyTyped

jigarcognino commented 1 year ago

@mikaello how can i use it(@types/react-mic) with vite.config.ts?

[vite]: Rollup failed to resolve import "react-mic" from "src/Input.tsx". This is most likely unintended because it can break your application at runtime. If you do want to externalize this module explicitly add it to build.rollupOptions.external

mikaello commented 1 year ago

I'm sorry, I got no experience with Vite, and haven't used this module for years, so I can't help you out here.