Skip to content

feat: add complete TypeScript declarations for @juspay-tech/hyper-js#18

Open
ArushKapoorJuspay wants to merge 2 commits intojuspay:mainfrom
ArushKapoorJuspay:feat/typescript-declarations
Open

feat: add complete TypeScript declarations for @juspay-tech/hyper-js#18
ArushKapoorJuspay wants to merge 2 commits intojuspay:mainfrom
ArushKapoorJuspay:feat/typescript-declarations

Conversation

@ArushKapoorJuspay
Copy link
Copy Markdown
Contributor

Summary

  • Fixes gaps in the existing src/index.d.ts (1098 → 1205 lines) to match the runtime API surface from hyperswitch-web/src/hyper-loader/Hyper.res
  • Adds compile-time type test file (src/index.test-d.ts, 556 lines, 42 test functions) verified by tsc --noEmit

Changes

EventData (fixed)

  • Replaced incorrect field names (focusTriggered/blurTriggered) with runtime-correct focus/blur
  • Now matches hyperswitch-web/src/hyper-loader/Types.res:5-17 exactly (11 fields)

New Types Added

  • EventName — 9-value string literal union for all SDK events
  • ComponentType — 14-value union for all creatable element types (card, payment, googlePay, applePay, klarna, paze, samsungPay, etc.)

HyperInstance (expanded)

Added 7 methods missing from the original declarations:

  • confirmOneClickPayment — one-click saved card confirmation
  • initPaymentSession / initAuthenticationSession — Click-to-Pay session lifecycle
  • paymentMethodsManagementElements — saved payment method management
  • completeUpdateIntent / initiateUpdateIntent — update intent flows
  • confirmTokenization — tokenization confirmation

PaymentElement (expanded)

  • Added onSDKHandleClick method for intercepting pay button clicks

Supporting Interfaces

  • ClickToPaySession, BrowserInfo, ConfirmOneClickPaymentParams, ConfirmTokenizationParams, etc.
  • Expanded LoadOptions with customBackendUrl, customLogUrl, customLoggingEndpoint

Type Tests

  • 556-line test file covering every exported type, interface, and method
  • Verified with tsc --noEmit (0 errors)

Source of Truth

The declarations match the runtime API from hyperswitch-web/src/hyper-loader/Hyper.res:804-818 (13 methods), NOT the outdated hyper-js/src/Types.res (9 methods). hyper-js is a thin script loader that passes through the object created by hyperswitch-web.

Testing

npx tsc --project tsconfig.test.json --noEmit  # 0 errors

Related PRs

  • juspay/react-hyper-js — TypeScript declarations for React wrapper
  • juspay/hyperswitch-web — Demo app converted to TypeScript

…pand HyperInstance with Click-to-Pay and headless methods

- Fix EventData to match runtime (Types.res:5-17): replace focusTriggered/blurTriggered with focus/blur/ready/completeDoThis/confirmTriggered/oneClickConfirmTriggered
- Remove incorrect Event/EventParam/EventHandler types (ReScript variant pattern not used at runtime)
- Add EventName literal union for type-safe event subscription
- Add ComponentType literal union for type-safe element creation
- Fix PaymentElement.on() signature to match runtime callback (EventData | undefined)
- Add PaymentElement.onSDKHandleClick() method
- Fix Element interface: use ComponentType, ElementsUpdateOptions, optional options param
- Add Click-to-Pay supporting types and session interfaces
- Add HyperInstance methods: confirmOneClickPayment, initPaymentSession, initAuthenticationSession, paymentMethodsManagementElements, completeUpdateIntent, initiateUpdateIntent, confirmTokenization
- Expand LoadOptions with isPreloadEnabled, isTestMode, isForceInit, redirectionFlags, analytics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant