DenoDDeno
Powered by
cowboydC
Denoβ€’3mo ago
cowboyd

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

🌍3rd Party ModuleπŸ§‘β€πŸ’»JS / TS Development
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;
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
deno lint
complains that
schema
schema
needs an explicit type because of the
no-slow-types
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?
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

types not inferred from npm packages
lvinLlvin / help
4y ago
Using Zod with ts-zod-decorators
Deno AI HelperDDeno AI Helper / help
2y ago
error[no-slow-types]: super class expression was too complex
mabasicMmabasic / help
4mo ago
no-slow-types should not trigger on 'as const' objects
kittyamazing_Kkittyamazing_ / help
2y ago