We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have taken the example from the migration guide for using forwardRef (https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#migrate-withref-to-forwardref) and added TypeScript type info to it and the result is a compile error. The code is complaining that the "ref" prop is not allowed.
import React from 'react'; import { injectIntl, WrappedComponentProps } from 'react-intl'; class MyComponent extends React.Component<WrappedComponentProps> { doSomething = () => console.log(this.state || null); render() { return <div>Hello World</div>; } } const MyComponentIntl = injectIntl(MyComponent, { forwardRef: true }); class Parent extends React.Component { myComponentRef = React.createRef<MyComponent>(); componentDidMount() { this.myComponentRef.current.doSomething(); // no need to call getWrappedInstance() } render() { return <MyComponentIntl ref={this.myComponentRef} />; } }
Produces the compile error:
Error:(22, 13) TS2322: Type '{ ref: RefObject<MyComponent>; }' is not assignable to type 'IntrinsicAttributes & Pick<WrappedComponentProps<"intl">, never> & { forwardedRef?: Ref<any>; } & { children?: ReactNode; }'. Property 'ref' does not exist on type 'IntrinsicAttributes & Pick<WrappedComponentProps<"intl">, never> & { forwardedRef?: Ref<any>; } & { children?: ReactNode; }'.
As a workaround, I can explicitly add the ref to the list of props on the component:
class MyComponent extends React.Component<WrappedComponentProps & { ref: RefObject<MyComponent> }>
npm ls react-intl
npm ls react
npm ls typescript
npm --version
The text was updated successfully, but these errors were encountered:
Thanks for reporting! We'll take a look asap.
Sorry, something went wrong.
45887bf
@TazmanianD can u try master?
fix: type def for forwardRef in injectIntl, fix #1444
840aac9
Unfortunately it didn't help me. dialog = React.createRef<ConfirmDialog>();
dialog = React.createRef<ConfirmDialog>();
'ConfirmDialog' refers to a value, but is being used as a type here.
this.dialog.current.handleOpen(... property handleOpen does not exist on type unknown ....
this.dialog.current.handleOpen(...
export default injectIntl(ConfirmDialog, { forwardRef: true });
No branches or pull requests
Current behavior
I have taken the example from the migration guide for using forwardRef (https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#migrate-withref-to-forwardref) and added TypeScript type info to it and the result is a compile error. The code is complaining that the "ref" prop is not allowed.
Produces the compile error:
As a workaround, I can explicitly add the ref to the list of props on the component:
Your Environment
npm ls react-intl
npm ls react
npm ls typescript
npm --version
The text was updated successfully, but these errors were encountered: