Skip to content

type reference inferred without | undefined without exactOptionalPropertyTypesΒ #1310

Closed

Description

@flodlc

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.

Activity

  1. added
    bug
    on Feb 14, 2025
  2. changed the title [-]reuse undefined type does not work[/-] [+]Reuse type with "undefined" looses "undefined"[/+] on Feb 14, 2025
  3. ssalbdivad commented on Feb 14, 2025

    @ssalbdivad
    Member

    I can't reproduce this:

    Image

    If you're still running into this issue locally, could you add a full repro?

  4. flodlc commented on Feb 14, 2025

    @flodlc
    Author

    We definitely don't have the same result.
    I will try in a minimal repo. Could you send me your tsconfig ?
    Image

  5. ssalbdivad commented on Feb 14, 2025

    @ssalbdivad
    Member

    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.

  6. added
    confirmed
    on Feb 14, 2025
  7. changed the title [-]Reuse type with "undefined" looses "undefined"[/-] [+]type reference inferred without ` | undefined` without `exactOptionalPropertyTypes`[/+] on Feb 14, 2025
  8. flodlc commented on Feb 14, 2025

    @flodlc
    Author

    Yes, I just got it too, setting "exactOptionalPropertyTypes": true makes it work.
    Thanks for the very fast support and for your work.

  9. flodlc commented on Feb 14, 2025

    @flodlc
    Author

    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.

  10. ssalbdivad commented on Feb 14, 2025

    @ssalbdivad
    Member

    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.

  11. moved this from To do to Planned in arktypeioon Feb 14, 2025
  12. moved this from Planned to Backlog in arktypeioon Feb 23, 2025
  13. added 3 commits that reference this issue on Oct 22, 2026
    1bf17e9
    d6ff28e
    efb65d0
  14. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  15. moved this from Backlog to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconfirmed

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions