arktype
arktype copied to clipboard
type reference inferred without ` | undefined` without `exactOptionalPropertyTypes`
Report a bug
🔎 Search Terms
undefined, optional
🧩 Context
- ArkType version: 2.0.4
- TypeScript version (5.1+): 5.7.3
- Other context you think may be relevant (JS flavor, OS, etc.):
🧑💻 Repro
It seems like an obvious bug so maybe it comes from a wrong usage. When I reuse a property type that can be undefined, it looses it's undefined type.
const age = type("number | undefined");
const User = type({
age: age,
});
const user = user({ age: undefined });
// user.age type is number, not mentions undefined.
I can't reproduce this:
If you're still running into this issue locally, could you add a full repro?
We definitely don't have the same result.
I will try in a minimal repo. Could you send me your tsconfig ?
It looks like this occurs with "exactOptionalPropertyTypes": false.
The docs recommend setting that flag to true, but undefined should not be stripped here regardless.
Will take a look and see if we can fix for the next release.
Yes, I just got it too, setting "exactOptionalPropertyTypes": true makes it work. Thanks for the very fast support and for your work.
The docs recommend setting that flag to true, but undefined should not be stripped here regardless.
Yes agree with this, it's actually not so obvious to set exactOptionalPropertyTypes to true in many projects.
Won't be able to address this right away in 2.1.0 since the immediate solutions I found had significant performance overhead, but will try and find something that works well as a followup.