arktype icon indicating copy to clipboard operation
arktype copied to clipboard

Investigate autocompleting index signatures

Open ssalbdivad opened this issue 11 months ago • 1 comments

Currently we don't support autocomplete within index signatures. I was able to get a POC of this working by adjusting the validateObjectLiteral type to something like this:

export type validateObjectLiteral<def, $, args> = {
  [k in keyof def as k extends `[${infer tail}${"]" | ""}`
    ? tail extends `${string}]`
      ? k
      : `[${validateString<tail, $, args>}]`
    : k]: k extends IndexedKey<infer indexDef>
    ? validateString<indexDef, $, args> extends error<infer message>
      ? // add a nominal type here to avoid allowing the error message as input
        indexParseError<message>
      : inferDefinition<indexDef, $, args> extends PropertyKey
      ? // if the indexDef is syntactically and semantically valid,
        // move on to the validating the value definition
        validateDefinition<def[k], $, args>
      : indexParseError<writeInvalidPropertyKeyMessage<indexDef>>
    : validateObjectValue<def[k], $, args>;
};

Another option would be to have a context param when parsing a string that indicated it was part of an index signature, and adjust completion suggestions accordingly.

One of these approaches should work well, but type perf tests are critical as this could easily be extremely inefficient if not done carefully.

ssalbdivad avatar Sep 05 '23 01:09 ssalbdivad