Why does an optional property add a " | undefined" instead of just being an optional property?

Hi, this feels like such a basic question that it probably has an answer, but I don't understand why marking a arktype property as optional not just makes the corresponding inferred type property optional, without adding an additional | undefined? I encountered something similar with zod which had the result that my zod-type and database generated type did not match although they should. Dummy example:
const schema = type({
'name?': 'string',
email: 'string.email'
});


// typeof schema.infer
// {
// email: string;
// name?: string | undefined;
// }

type WhatIWanted = {
name?: string;
email: string;
}
const schema = type({
'name?': 'string',
email: 'string.email'
});


// typeof schema.infer
// {
// email: string;
// name?: string | undefined;
// }

type WhatIWanted = {
name?: string;
email: string;
}
https://github.com/colinhacks/zod/issues/3186
GitHub
optional should not add undefined to type signature · Issue #3186 ·...
I'm sorry if this is a duplicate, I could not find an existing issue or discussion that seemed to be exactly about the following. It's really rather simple: the following schema infers the ...
3 Replies
ssalbdivad
ssalbdivad•3d ago
This doesn't have anything to do with arktype and just depends on wheter you have exactOptionalPropertyTypes enabled in your tsconfig. I recommend enabling it which removes the |undefined
einarpersson
einarpersson•3d ago
thank you! gosh there is so much typescript stuff to know about
ssalbdivad
ssalbdivad•3d ago
If you care enough to ask about stuff like that you will learn most of what you need pretty quickly and then it will only be occasionally you learn about something unfamiliar. Kinda fun though when there's more to explore 😛
Want results from more Discord servers?
Add your server