Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to allow undefined for optional properties #1191

Open
JesusTheHun opened this issue Oct 30, 2024 · 4 comments
Open

Add an option to allow undefined for optional properties #1191

JesusTheHun opened this issue Oct 30, 2024 · 4 comments
Labels
confirmed The maintainers of the repo would like to address this

Comments

@JesusTheHun
Copy link

Request a feature

Add a global option to allow undefined as a value for optional properties.

configure({ optionalAllowsUndefined: true });

🤷 Motivation

const arkUser = type({ phoneNumber: 'string?' });

The type above produces the type { phoneNumber?: string } and will not validate { phoneNumber: undefined } at runtime.

💡 Solution

Another solution could be a new-ish syntax like string??.

@github-project-automation github-project-automation bot moved this to To do in arktypeio Oct 30, 2024
@ssalbdivad ssalbdivad added the confirmed The maintainers of the repo would like to address this label Oct 30, 2024
@Asfamilybank
Copy link

Are there any updates?🧐

@ssalbdivad
Copy link
Member

I would accept external contributions on this. Otherwise it would likely be sometime after stable 2.0.

@LukeAbby
Copy link

Out of merely interest is there actually any way to get exactly this proposed API to work?

configure({ optionalAllowsUndefined: true });

Traditionally I've had to have something like this:

configure({ optionalAllowsUndefined: true });

declare module "arktype/configuration" {
    interface Config {
        optionalAllowsUndefined: true
    }
}

@ssalbdivad
Copy link
Member

ssalbdivad commented Dec 17, 2024

ArkType uses a global called ArkEnv for type-level configuration, e.g.:

image

This is something I'm working on documenting more now.

However, this wouldn't be a type-level config. You would just change this setting to match the exactOptionalPropertyTypes option in your tsconfig. Only the runtime behavior would need to be configured from within ArkType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed The maintainers of the repo would like to address this
Projects
Status: Backlog
Development

No branches or pull requests

4 participants