arktypea
arktype10mo ago
Genshii

Get ts type that accepts type arguments

I have a type that looks like this:

interface PluginInstance<Input, TInput, Diff> {
  details: PluginDetails
  input: PluginInput<Input>
  transform: PluginTransform<Input, TInput> | undefined
  diff: PluginDiff<TInput, Diff>
  handle: PluginHandle<Diff, TInput>
  update: PluginUpdate | undefined
}


I would prefer to instead define a Type and infer the ts type.

const pluginInstanceSchema = type({
  "+": "reject",
  details: pluginDetails,
  input: type("Function").as<PluginInput>(),
  transform: type("Function").as<PluginTransform | undefined>(),
  diff: type("Function").as<PluginDiff>(),
  handle: type("Function").as<PluginHandle>(),
  update: type("Function").as<PluginUpdate | undefined>(),
})


So ultimately I'd want to do this:

type PluginInstance = typeof pluginInstanceSchema.infer
type ReturnsPluginInstance<Input, TInput, Diff> = (input: Input) => PluginInstance<Input, TInput, Diff>


But of course PluginInstance doesn't take any type arguments. Is it possible to define generics on my schema and have the inferred type accept those type arguments?

I tried playing around with scopes, tried doing const pluginInstanceSchema = type("<Input, TInput, Diff>", { ..., but didn't really get anywhere.
Was this page helpful?