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

Incorrect discriminated union processing #1033

Closed
TizzySaurus opened this issue Jul 2, 2024 · 1 comment
Closed

Incorrect discriminated union processing #1033

TizzySaurus opened this issue Jul 2, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@TizzySaurus
Copy link
Contributor

TizzySaurus commented Jul 2, 2024

Report a bug

🔎 Search Terms

boolean unioned with a recursive discriminated union, recursion, recursive discriminated union

🧩 Context

  • ArkType version: 2.0-dev.26
  • TypeScript version (5.1+): 5.5
  • Other context you think may be relevant (JS flavor, OS, etc.): N/A

🧑‍💻 Repro

import { scope } from "arktype"

const $ = scope({
    TypeWithNoKeywords: { type: "'boolean'|'null'" },
    TypeWithKeywords: "ArraySchema|ObjectSchema", // without both ArraySchema and ObjectSchema there's no error
    // "#BaseSchema": "TypeWithNoKeywords|boolean", // errors even with union reversed
    "#BaseSchema": "boolean|TypeWithNoKeywords", // without the `boolean` there's no error (even if still union such as `string|TypeWithNoKeywords`)
    ArraySchema: {
        "additionalItems?": "BaseSchema", // without this recursion there's no error
        type: "'array'"
    },
    // If `ObjectSchema` doesn't have `type` key there's no error
    ObjectSchema: {
        type: "'object'"
    }
})
export const JsonSchema = $.export() // TypeError: Cannot use 'in' operator to search for 'type' in false

The validateObjectLiteral type doesn't account for the => operator and when it discovers an unaccounted for operator it assumes it's the = (default) operator. I'm guessing this is the cause.

@TizzySaurus TizzySaurus added the bug Something isn't working label Jul 2, 2024
@github-project-automation github-project-automation bot moved this to To do in arktypeio Jul 2, 2024
@ssalbdivad ssalbdivad moved this from To do to Planned in arktypeio Jul 9, 2024
@ssalbdivad ssalbdivad moved this from Planned to Backlog in arktypeio Jul 26, 2024
@ssalbdivad
Copy link
Member

This is resolved as of 2.0.0-rc.7 🎉

@github-project-automation github-project-automation bot moved this from Backlog to Done (merged or closed) in arktypeio Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done (merged or closed)
Development

No branches or pull requests

2 participants