Skip to content

[TypeScript] TS type fields required where v2 spec marks them optional #1154

@ryanRfox

Description

@ryanRfox

Several TypeScript interface fields in @x402/core are defined as required but are marked optional in the v2 spec. The Zod schemas already have them optional, so runtime validation is correct, but the TypeScript types are stricter than both the spec and the schemas.

ResourceInfo.description and ResourceInfo.mimeType

typescript/packages/core/src/types/payments.ts L3-L7

The v2 spec (section 5.1.2, ResourceInfo table) marks both description and mimeType as Optional. The Zod schema in schemas/index.ts already has them as optional (z.string().optional()), but the TypeScript interface has both as required string.

PaymentPayload.resource

typescript/packages/core/src/types/payments.ts L27-L33

The v2 spec (section 5.2.2, PaymentPayload table) marks resource as Optional. The Zod schema (PaymentPayloadV2Schema) already has resource: ResourceInfoSchema.optional(), but the TypeScript interface has it as required.

Note: PaymentRequired.resource is correctly required in both the TS type and the spec -- no change needed there.

Mirrored in @x402/paywall

typescript/packages/http/paywall/src/types.ts L36-L40

The inline resource type within PaymentRequired mirrors the same required description and mimeType fields. Should also be made optional to stay consistent with @x402/core.

Impact

  • Code consuming these types must provide values the spec does not require
  • The mismatch between Zod schemas (correct) and TS interfaces (too strict) creates confusion about which is authoritative

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions