TextField TS Error with `variant` prop
See original GitHub issueWhen passing a conditional statement to the variant
prop of the TextField component like this:
<TextField
variant={isLongTextQuestion ? "outlined" : "standard"}
...
/>
I get a typescript error saying:
Types of property 'variant' are incompatible.
Type '"standard" | "outlined"' is not assignable to type '"outlined"'.
Type '"standard"' is not assignable to type '"outlined"'.ts(2322)
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
TextField
component should allow this statement as it accepts both outlined
and standard
independently.
Current Behavior 😯
Gives typescript type error
Steps to Reproduce 🕹
Link:
https://codesandbox.io/s/mor0mrooz9
Context 🔦
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v3.9.3 |
React | v16.8.4 |
Browser | |
TypeScript | |
etc. |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:13 (5 by maintainers)
Top Results From Across the Web
How do I pass in the variant property of the material-ui ...
OutlinesTextFieldProps needs a value of 'outlined' for variant ... The issue is that the value of variant is not known at compile time....
Read more >TextField API - Material UI - MUI
Name Type Default
autoComplete string
autoFocus bool false
classes object
Read more >Useful Patterns by Use Case - React TypeScript Cheatsheets
{/* Error: Property 'toPrecision' does not exist on type 'string'. ... As of TS 2.9, you can also supply the type parameter in...
Read more >Input - Chakra UI
The input component comes in 4 variants: outline , unstyled , flushed , and filled . Pass the variant prop and set it...
Read more >API - React Select
These base props are those available to be passed to all select variants. ... HTML ID of an element containing an error message...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I figured out a workaround. For anyone else who sees this, try this:
It’s far from ideal though as the only purpose of this entire function is to fix the
props.variant
bug.fuck dat and do this: