Object destruction in functions can be cumbersome. Using defaults makes it slightly easier, but it would be great if it could be written in a simpler way.
π Motivating Example
// The current way of doing object destructuring in function declarations// is cumbersome, lengthy, and repetitive // π₯ΊfunctionRectangle({
width,
height,
fill
}: {width: numberheight: numberfill: 'dark'|'light'}){}// π ... maybe this could be done "nicer" by just providing the type?functionRectangle({width:number,height:number,fill: 'dark'|'light'}){}// π€ Currently, we can use defaults to achieve something along this line:functionRectangle({width =200, height =200, fill ='dark'}){}// ... , but `fill` would not be typed correctly π₯Ί and maybe we don't want // to use default values in the first place// π Could this be the way to do it with correctly typed defaults? functionRectangle({width =200, height =200,fill: 'dark'|'light'='dark'}){}// π ...or kind of "mixed" mode? functionRectangle({width =200, height =200,fill: 'dark'|'light'}){}
π» Use Cases
This is a common pattern in React code.
The text was updated successfully, but these errors were encountered:
Nicer object destructuring in function declarations
object destructuring function declarations
My suggestion meets these guidelines (I guess):
Object destruction in functions can be cumbersome. Using defaults makes it slightly easier, but it would be great if it could be written in a simpler way.
This is a common pattern in React code.
The text was updated successfully, but these errors were encountered: