Skip to content

Commit

Permalink
[TextField] fix typescript complications when 'component' prop is pas…
Browse files Browse the repository at this point in the history
…sed to FormHelpterTextProps
  • Loading branch information
AlexAndriyanenko committed Apr 13, 2020
1 parent 8e2f0cc commit a150ab9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/material-ui/src/TextField/TextField.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export interface BaseTextFieldProps
/**
* Props applied to the [`FormHelperText`](/api/form-helper-text/) element.
*/
FormHelperTextProps?: Partial<FormHelperTextProps>;
FormHelperTextProps?: FormHelperTextProps<
React.ElementType,
{ component: React.ElementType | JSX.Element }
>;
/**
* If `true`, the input will take up the full width of its container.
*/
Expand Down
18 changes: 17 additions & 1 deletion packages/material-ui/src/TextField/TextField.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import TextField from '@material-ui/core/TextField';
import TextField, { TextFieldProps } from '@material-ui/core/TextField';

{
// https://github.com/mui-org/material-ui/issues/12999
Expand Down Expand Up @@ -67,3 +67,19 @@ function FocusHandlerTest() {

return null;
}

function createElementTextFieldTest() {
// $ExpectError
React.createElement<TextFieldProps>(TextField, {
FormHelperTextProps: {
component: 'some-wrong-element',
},
});

// $ExpectError
React.createElement<TextFieldProps>(TextField, {
FormHelperTextProps: {
component: 1234,
},
});
}

0 comments on commit a150ab9

Please sign in to comment.