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
When TypeScript compiler option exactOptionalPropertyTypes is set to true, you cannot pass undefined as a value to an object property that is marked as optional but without explicit undefined type. While IMO very useful option, it can lead to bad DX, because it can cause TypeScript errors:
import{Checkbox}from'@headlessui/react';typeCustomComponentProps={name?: string|undefined;}letCustomComponent=({name}: CustomComponentProps)=>{return<Checkboxname={name}/>;// error here, because `name` prop can be `undefined`}
I therefore prefer that "input" types (like function parameters, properties in options objects, etc.) have explicit undefined added to them; e.g. here should look like this:
Describe the bug and the expected behavior
When TypeScript compiler option
exactOptionalPropertyTypes
is set totrue
, you cannot passundefined
as a value to an object property that is marked as optional but without explicitundefined
type. While IMO very useful option, it can lead to bad DX, because it can cause TypeScript errors:I therefore prefer that "input" types (like function parameters, properties in options objects, etc.) have explicit
undefined
added to them; e.g. here should look like this:Would it be possible to add
undefined
to all input types? Thank you.The text was updated successfully, but these errors were encountered: