TypeScript props interface is cast to never when theme prop is not given and BaseStyledInterface is used
See original GitHub issueThis line (L66) was recently added, and it causes an edge case in a very specific (but common) use case:
Here we set the theme prop to be optional when P extends { theme?: T; }
. But by default T
is any
in the exposed BaseStyledInterface
.
This causes WithOptionalTheme
to exhibit the bug. It then casts P
to never
. That means that the resulting interface is just: { theme?: any }
.
The bug disappears when T
is not any
, meaning when theme
is set to something else.
Here is an image of @JonWallsten’s reproduction: http://imgur.com/a/i1GrD
The interface of ICombinedSpinButton
is:
export interface ICombinedSpinButton extends IAutoplayButton {
autoplayActive?: boolean
autoplayRunning?: boolean
hidden?: boolean
}
(Ignore the extend, it’s irrelevant)
Note that the theme
property is not cast to a type.
cc @Igorbek
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Using styled components with Typescript, prop does not exist?
I get warnings that: Property 'emphasized' does not exist on type 'ThemedStyledProps<DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, ...
Read more >Typing defaultProps - React TypeScript Cheatsheets
The consensus is to use object default values. Function Components: type GreetProps = { age ...
Read more >Defining exclusive properties with TypeScript - miyauci.me
Shows how to define exclusive properties in TypeScript. It explains the background ... In one interface, the property color is used to specify...
Read more >TypeScript - Material UI - MUI
Many components concerned with user input offer a value prop or event handlers which include the current value . In most situations that...
Read more >Google TypeScript Style Guide
Do not mark interfaces specially ( IMyInterface or MyFooInterface ) unless it's idiomatic in its environment. When introducing an interface for a class,...
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 FreeTop 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
Top GitHub Comments
I’ll release a minor version today containing this fix
This will throw an error in
StyledDumbBox
Reverting to
2.1.1
fixes the build error.