-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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
- [TypeScript] Duplicate ResourceInfo interface in server code with different optionality #1155 -- Duplicate
ResourceInfointerface in server code diverges once this is fixed - [TypeScript] SIWX settle hook crashes if PaymentPayload.resource is undefined #1156 -- SIWX settle hook crashes if
PaymentPayload.resourceis undefined (latent bug exposed by this fix)