Material-ui: [TextareaAutosize] Property 'ref' does not exist on type

Created on 17 Sep 2019  路  3Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

When passing ref to TextareaAutosize typescript complains about Property 'ref' does not exist on type.

Expected Behavior 馃

Since the component uses forwardRef, the types should reflect this and typescript shouldn't complain when using the ref prop.

Steps to Reproduce 馃暪

link to codesandbox

function Example() {
  const inputRef = React.useRef();

  return <TextareaAutosize ref={inputRef} />;
}

Steps:

  1. Import TextareaAutosize in a typescript project
  2. Pass ref prop TextareaAutosize
  3. Error

Context 馃敠

Trying to extend the TextField component and having to use // @ts-ignore to get past this.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.4.2 |
| React | v16.8.4 |
| TypeScript | v3.3.3 and v3.5.3 |

bug 馃悰 TextareaAutosize good first issue hacktoberfest typescript

All 3 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

finaiized picture finaiized  路  3Comments

revskill10 picture revskill10  路  3Comments

newoga picture newoga  路  3Comments

ericraffin picture ericraffin  路  3Comments

reflog picture reflog  路  3Comments