Why are the partial operator `?` and explicit `undefined` incompatible?
I define the type:
I don’t understand why it is designed like this, as far as I know, partial operator will accept explicit
undefined in TypeScript. (or I’m wrong ?)🤨
#questions #typescript9 Replies
I can only guess as to why ArkDavid decided to design it this way since I am not him.
It's probably because of exactOptionalPropertyTypes
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
There are a number of functions where passing
{ x: undefined } will cause an error but {} will not
for example
Will error when called as doesStuff({ x: undefined })ArkType explicitly requires you to use
exactOptionalPropertyTypes
If you don't, you should get a type error saying to add it to tsconfigtsconfig.json? Including when packing.exactOptionalPropertyTypes in global?
I try it:
or
None of them take effectNo, it's a requirement, not a flag
Nvm is was strictNullChecks

Installation You'll also need... - TypeScript versionBut how to use>=5.1. - Apackage.jsonwith"type": "module"(or an environment that supports ESM imports) - Atsconfig.jsonwith... -strictorstrictNullChecks(required) -skipLibCheck(strongly recommended, see FAQ) -exactOptionalPropertyTypes(recommended)
exactOptionalPropertyTypes=false 🤔
@Asfamilybank for now just be verbose and
I guessGitHub
Add an option to allow
undefined for optional properties · Issue ...Request a feature Add a global option to allow undefined as a value for optional properties. configure({ optionalAllowsUndefined: true }); 🤷 Motivation const arkUser = type({ phoneNumber: 'stri...
I don't want to change the existing ts configuration because that would require me to refactor the entire project's code.
I think this plan is pretty good.