@anvilco/types

中文文档
0.2.5发布于 2026/11/06MITTypeScriptESM + CJS零依赖近 30 天下载 2263

TypeScript types generated from the Anvil OpenAPI spec and GraphQL schema

原始使用文档

@anvilco/types

TypeScript types generated from the Anvil OpenAPI spec and GraphQL schema. Consumed internally by @anvilco/browser and @anvilco/react.

The one place for the Anvil SDK's TypeScript types:

  • REST: paths, components and operations, generated from the OpenAPI spec, plus the fill-PDF request types (FillPdfPayload, FillPdfData, FillPdfOptions).
  • Etch: CreateEtchPacketArgs, the createEtchPacket mutation's arguments with the ones the GraphQL schema calls JSON typed: signers (EtchSigner), signaturePageOptions (EtchSignaturePageOptions) and finishPageOptions (EtchFinishPageOptions). The OpenAPI spec publishes their shapes.
  • GraphQL: the GraphQL namespace, generated from the schema.
  • The SDK's own types: AnvilOptions, GraphQLResponse, RESTResponse, ResponseError, ResponseErrorField, RuntimeError and Abortable.
import type { GraphQL } from '@anvilco/types'

type Packet = GraphQL.Type<'EtchPacket'> // any type in the schema, by name
type WeldFile = GraphQL.Type<'WeldFile'> // input types too: nullable fields are optional
type Args = GraphQL.MutationArgs<'createEtchPacket'> // the arguments of any mutation
type PacketArgs = GraphQL.QueryArgs<'etchPacket'> // …or query

Object types describe the whole object as the schema defines it. A query returns only the fields it selects, so for data you fetched, use the type of your query's result instead.

Custom scalars are typed by GraphQL.Scalars: Date is an ISO 8601 string, JSON is unknown, and Upload is Blob | { data: string; mimetype: string; filename: string } | { url: string; filename?: string }.

GraphQL operations

To run queries and mutations, use @anvilco/core. Its graphql documents are typed against this schema.

The specs these types are generated from also ship with the package, for build tooling: the GraphQL schema at @anvilco/types/schema.graphql and the OpenAPI spec at @anvilco/types/openapi.json. The other Anvil API clients (python-anvil, dotnet-anvil) generate their types from them, so every client describes the same API. Importing @anvilco/types never loads them at runtime.

Regenerating

Types are regenerated from production after every Anvil production deploy (.github/workflows/sync-api-types.yml), which opens a PR when they change. To regenerate by hand:

  • REST: yarn workspace @anvilco/types generate:rest refreshes schema/openapi.json from production and rebuilds src/rest.ts from it.
  • GraphQL: ANVIL_API_KEY_PROD_BASE64=... yarn workspace @anvilco/types fetch:schema refreshes schema/anvil-schema.graphql from production, then yarn workspace @anvilco/types generate:graphql rebuilds src/graphql/generated/ from it. The second step needs no network access or key, which is what CI checks.

版本与发布记录

@anvilco/types 共发布 7 个版本,首次发布于 2026/05/20;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.2.5latest2026/11/061 天前
0.2.42026/11/061 天前
0.2.32026/10/2910 天前
0.2.22026/10/2217 天前
0.2.12026/10/2217 天前
0.2.02026/10/1523 天前

关于 @anvilco/types 的常见问题

@anvilco/types 是什么?

TypeScript types generated from the Anvil OpenAPI spec and GraphQL schema

如何安装 @anvilco/types?

在项目目录运行 npm install @anvilco/types,或使用 pnpm add / yarn add / bun add。

@anvilco/types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anvilco/types 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anvilco/types 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anvilco/types 可以商用吗?

@anvilco/types 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@anvilco/types 的下载量有多少?

根据 npm 官方下载统计,@anvilco/types 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,263 次,日均约 75 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anvilco/types 还在维护吗?

最新版本 0.2.5 发布于 2026/11/06(1 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/05/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。