When passing ref to TextareaAutosize typescript complains about Property 'ref' does not exist on type.
Since the component uses forwardRef, the types should reflect this and typescript shouldn't complain when using the ref prop.
function Example() {
const inputRef = React.useRef();
return <TextareaAutosize ref={inputRef} />;
}
Steps:
Trying to extend the TextField component and having to use // @ts-ignore to get past this.
| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.4.2 |
| React | v16.8.4 |
| TypeScript | v3.3.3 and v3.5.3 |
Confirmed, it also affects ClickAwayListener and Portal. The difference between the other component is the absence of StandardProps.
This seems to do the trick:
diff --git a/packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts b/packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts
index 7daca851a..604a605ef 100644
--- a/packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts
+++ b/packages/material-ui/src/TextareaAutosize/TextareaAutosize.d.ts
@@ -4,6 +4,10 @@ export interface TextareaAutosizeProps extends React.TextareaHTMLAttributes<HTML
rowsMax?: string | number;
}
-declare const TextareaAutosize: React.ComponentType<TextareaAutosizeProps>;
+declare const TextareaAutosize: React.ComponentType<
+ TextareaAutosizeProps & {
+ ref?: TextareaAutosizeProps extends { ref?: infer RefType } ? RefType : React.Ref<unknown>;
+ }
+>;
export default TextareaAutosize;
Should we abstract it, somehow?
Is anyone working on this? I would like to help.
@ivandevp You are free to go :)