Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Validated completions available for string props are not available for shallow strings #53997

Copy link
Copy link
@ssalbdivad

Description

@ssalbdivad
Issue body actions

Bug Report

I encountered this bug while adding autocomplete support for ArkType. The goal is for completions to behave the same way whether they are parsed at an object key like type({a: "string|"}) or via a shallow string definition like type("string|").

However, autocompletions for expressions like these unexpectedly fail for the shallow case despite succeeding when defined in an object.

🔎 Search Terms

completions, autocomplete, strings, expressions, parsing, arktype

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

💻 Code

type keyword = "foo" | "bar" | "baz"

type validateString<s> = s extends keyword
    ? s
    : s extends `${infer left extends keyword}|${infer right}`
    ? right extends keyword
        ? s
        : `${left}|${keyword}`
    : keyword

type isUnknown<t> = unknown extends t
    ? [t] extends [{}]
        ? false
        : true
    : false

type validate<def> = def extends string
    ? validateString<def>
    : isUnknown<def> extends true
    ? keyword
    : {
          [k in keyof def]: validate<def[k]>
      }

const parse = <def>(def: validate<def>) => def

// typing "f" autocompletes to "foo"
const shallowKeyword = parse("foo")

// typing "foo|b" does not autocomplete but yields the following type error if left incomplete:
// Argument of type '"foo|b"' is not assignable to parameter of type '"foo|foo" | "foo|bar" | "foo|baz"'
// @ts-expect-error
const shallowExpression = parse("foo|b")

// typing "f" autocompletes to "foo"
const deepKeyword = parse({ k: "foo" })

// typing "foo|b" autocompletes to "foo|bar" | "foo|baz"
const deepExpression = parse({ k: "foo|bar" })
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.