Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: type issue with components ref #653

Closed
TommyBacco opened this issue Jun 21, 2024 · 6 comments · Fixed by #657
Closed

Typescript: type issue with components ref #653

TommyBacco opened this issue Jun 21, 2024 · 6 comments · Fixed by #657
Assignees
Labels
new Flag for new issues before someone replies released

Comments

@TommyBacco
Copy link

It looks like there is some misalignment in the types when passing a ref making necessary to suppress the type error in order to proceed and use the components programmatically.

image

@github-actions github-actions bot added the new Flag for new issues before someone replies label Jun 21, 2024
@Emkay2309
Copy link

Does Sidetab component excepts ref or not ???
Check that first ,
if it does try providing a type to ref as well

interface SidetabProps extends React.HTMLAttributes {
ref ?: React.Ref;
}

ref?: React.Ref;

@FranRom
Copy link

FranRom commented Jul 3, 2024

The same is happening in the PopupButton and ref is in the documentation:
https://github.com/Typeform/embed/tree/main/packages/embed-react#passing-a-custom-ref

The error I get is:
Type '{ children: string; ref: MutableRefObject<undefined>; id: string; hidden: { user: string; }; className: string; onSubmit: () => void; }' is not assignable to type 'IntrinsicAttributes & BaseOptions & ModalWindowOptions & UrlOptions & ActionableOptions & ... 5 more ... & ButtonComponentBaseProps'. Property 'ref' does not exist on type 'IntrinsicAttributes & BaseOptions & ModalWindowOptions & UrlOptions & ActionableOptions & ... 5 more ... & ButtonComponentBaseProps'

@mathio
Copy link
Contributor

mathio commented Jul 16, 2024

Hello @TommyBacco @FranRom

how do you define your ref? When i define it like this it works for me:

const ref = useRef();

There are no TS errors on props or ref:
Screenshot 2024-07-16 at 08 58 27

But it is true the ref is not typed properly, as it does not define the open method.
I will look into this, if we can supply correct types on our side. In the meantime, as a workaround, I'd suggest typing as any.

Edit: Actually we do have a GenericEmbed type that you can use on your side to type the ref, like this:

import { GenericEmbed } from "@typeform/embed-react/build/components";
const ref = useRef<GenericEmbed>();
const openPopup = () => ref.current?.open();

@mathio mathio self-assigned this Jul 16, 2024
@mathio
Copy link
Contributor

mathio commented Jul 16, 2024

Actually you are right. I was building my test project via vite. When I build with tsc --build the typescript did complain.

It proved to be quite challenging to type properly when we reuse React's forwardRef. I am renaming the prop instead to embedRef (since this is not actually a DOM element ref). Upcoming @typeform/embed-react version will introduce this breaking change in #657.

@typeform-ops-gha
Copy link

🎉 This issue has been resolved in version @typeform/embed-v5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@typeform-ops-gha
Copy link

🎉 This issue has been resolved in version @typeform/embed-react-v4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new Flag for new issues before someone replies released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants