react-typeform-embed icon indicating copy to clipboard operation
react-typeform-embed copied to clipboard

Error when using with Typescript

Open thenakulchawla opened this issue 4 years ago • 1 comments
trafficstars

When I import it the way it is shown in the README file. It gives the below error:

Could not find a declaration file for module 'react-typeform-embed'. 'path_in_node_mdulesreact-typeform-embed/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/react-typeform-embed` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-typeform-embed';`

It gives a 404 when I try to install with types.

thenakulchawla avatar Feb 28 '21 23:02 thenakulchawla

For now, I had to add the types myself.

In index.d.ts, in root of the project:

// declares only one of the functions, see more here:
// https://github.com/alexgarces/react-typeform-embed
declare module "react-typeform-embed" {
	export type PopupProps = {
		id: string;
		height?: number;
		width?: number;
		size?: number;
		hidden?: Record<string, string>;
		onSubmit?: () => void;
		hideHeaders?: boolean;
		disableAutoFocus?: boolean;
		enableSandbox?: boolean;
	};

	export function Popup(props: PopupProps): JSX.Element;
}

I've only added the Popup that I use, and pretty sure that I did not specify all of the props, you can add the ones you need yourself.

MonstraG avatar Feb 03 '22 10:02 MonstraG