TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

Setting Optional Props with a Default in React

Open mattferderer opened this issue 7 years ago • 0 comments

TypeScript 3.0 made setting default props much simpler in React. The release notes for 3.0 show an example.

What isn't clear is how to set these default props as optional.

It appears the proper way is to just set the defaultProps and leave any question mark off of the prop interface.

This seems to confuse other tools that look for that question mark. Before I try suggesting to hard for those other tools to fix it, is the above the correct method for setting optional props? Do we just leave the question mark off the interface? Using a question mark seems to give an undefined is not assignable to type 'xxxx' error.

mattferderer avatar Oct 02 '18 14:10 mattferderer