cowboydC
Denoβ€’3d ago
cowboyd

Using inferred types from libs like `zod` and `arktype` with the `no-slow-types` rule

A persistent problem that I encounter is when I have inferred types defined by a runtime validation library that are part of a module's public API. For example, here is a type schema with two exported types:

import { scope } from "arktype";

const schema = scope({
  ContextData: {
    values: "object.json",
  },
  ContextNode: {
    data: "ContextData",
    children: "ContextNode[]",
  },
}).export();

export type ContextData = typeof schema.ContextData.infer;
export type ContextNode = typeof schema.ContextNode.infer;


deno lint complains that schema needs an explicit type because of the no-slow-types rule, which makes sense, but at the same time it adds a significant burden to the upkeep because the only solution I've been able to come up with is to define the types both statically and dynamically, and then write a test case to make sure that they don't diverge.

My question: Is there a way to do this that does not involve this maintenance overhead?
Was this page helpful?