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

Dynamic context property access #1187

Open
andreisaikouski opened this issue Jun 14, 2023 · 0 comments
Open

Dynamic context property access #1187

andreisaikouski opened this issue Jun 14, 2023 · 0 comments

Comments

@andreisaikouski
Copy link

andreisaikouski commented Jun 14, 2023

I am trying to validate a field whose struct depends on another field, as in issue 123.

The docs specify very little on the dynamic utility and no information on the context type

In essence I am trying to do

enum UserType {
    USER = 'USER',
    ADMIN = 'ADMIN',
}

const myUser = object({
    type: enums(Object.value(UserType)),
    // email should be optional for ADMIN type and required for USER type
    email: dynamic( (value, context) =>
         context.type === UserType.USER ? string() : optional(string())
    )
})

This has several issues, mostly because the context is not as used in the referenced issue.
Is there any additional documentation or clarity on this?

Intellisense shows:
image

Error:

error TS2339: Property 'type' does not exist on type 'Context'.
    c.type === UserType.USER

Superstruct version 1.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant