Skip to content

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

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

Closed
ssalbdivad opened this issue Apr 24, 2023 · 1 comment · Fixed by #53996
Closed
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@ssalbdivad
Copy link

ssalbdivad commented Apr 24, 2023

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" })
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Help Wanted You can do this labels Apr 25, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 25, 2023
@ssalbdivad
Copy link
Author

@Andarist mentioned this may be fixed by #54121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants