Skip to content

[TypeScript] Duplicate ResourceInfo interface in server code with different optionality #1155

@ryanRfox

Description

@ryanRfox

@x402/core exports two separate ResourceInfo interfaces from different entry points:

Wire format type (@x402/core/types)

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

Server configuration type (@x402/core/server)

typescript/packages/core/src/server/x402ResourceServer.ts L31-L35

Both are named ResourceInfo, both have url, description, and mimeType. The server version has description and mimeType as required. The wire format version currently also has them as required, but once #1154 is addressed the wire format will have them as optional per the v2 spec, creating a divergence between two identically-named interfaces.

Why this is confusing

  • Importing ResourceInfo from the wrong entry point gives a type with different optionality
  • TypeScript won't flag structural compatibility issues between them since the required version is assignable to the optional version, but not vice versa
  • The server version's JSDoc says "Resource information for PaymentRequired response" -- suggesting it represents the same concept as the wire format type

Possible fixes

  1. Have the server import and re-export from types/payments.ts -- eliminates the duplication. Server code that constructs these values would need to handle the optional fields.
  2. Rename the server version (e.g., RouteResourceInfo or ResourceConfig) -- makes the distinction explicit.
  3. Keep both but document the difference -- least disruptive but doesn't fix the naming collision.

Related

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