You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
typekeyword="foo"|"bar"|"baz"typevalidateString<s>=sextendskeyword
? s
: sextends `${infer leftextendskeyword}|${infer right}`
? rightextendskeyword
? s
: `${left}|${keyword}`
: keywordtypeisUnknown<t>=unknownextendst
? [t]extends[{}]
? false
: true
: falsetypevalidate<def>=defextendsstring
? validateString<def>
: isUnknown<def>extendstrue
? keyword
: {[kinkeyofdef]: validate<def[k]>}constparse=<def>(def: validate<def>)=>def// typing "f" autocompletes to "foo"constshallowKeyword=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-errorconstshallowExpression=parse("foo|b")// typing "f" autocompletes to "foo"constdeepKeyword=parse({k: "foo"})// typing "foo|b" autocompletes to "foo|bar" | "foo|baz"constdeepExpression=parse({k: "foo|bar"})
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 liketype("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
⏯ Playground Link
Playground link with relevant code
💻 Code