You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
styleProps is currently repeating the same mistakes as React.FC with children.
By default it assumes a generic shape that can result in writing code that's impossible at runtime when we should be able to verify it statically
Examples 馃寛
constFancySpan=styled('span')(({ styleProps })=>{constsize=styleProps?.size;if(typeofsize!=='number')thrownewTypeError('Expected a number')return{height: size+5}});<FancySpanstyleProps={{size: 1}}/>;
Motivation 馃敠
This currently type-checks when it should fail:
constFancySpan=styled('span')(({ styleProps })=>{constsize=styleProps?.size;if(typeofsize!=='number')thrownewTypeError('Expected a number')return{height: size+5}});// currently type-checks but fails at runtime<FancySpanstyleProps={{size: ''}}/>;constFancyDiv=styled('span')()// @ts-expect-error There are no styleProps. Passing this is an author error that should be caught<FancyDivstyleProps={{}}/>;
Note that you can get better type-safety with explicit prop shapes but considering past experience with implicit props this should be default:
Summary 馃挕
styleProps
is currently repeating the same mistakes asReact.FC
withchildren
.By default it assumes a generic shape that can result in writing code that's impossible at runtime when we should be able to verify it statically
Examples 馃寛
Motivation 馃敠
This currently type-checks when it should fail:
Note that you can get better type-safety with explicit prop shapes but considering past experience with implicit props this should be default:
styleProps
should be explicitly declared not implicitly provided consideringstyled
does not inject such a prop.The text was updated successfully, but these errors were encountered: