WithOptional
typetype WithOptional = TConfig extends { required: true }
? TResolved
: "default" extends keyof TConfig
? TResolved
: TResolved | undefined;Wrap a resolved type with undefined if the option is optional.
Required options or options with defaults are never undefined.
Uses 'key' extends keyof TConfig instead of TConfig extends { key: unknown }
to properly detect OPTIONAL properties. The latter check fails for optional
properties because { default?: X } doesn't guarantee default exists.