Skip to content

feat(demo-app): convert Hyperswitch-React-Demo-App to TypeScript#1485

Open
ArushKapoorJuspay wants to merge 2 commits intojuspay:mainfrom
ArushKapoorJuspay:feat/typescript-demo-app-clean
Open

feat(demo-app): convert Hyperswitch-React-Demo-App to TypeScript#1485
ArushKapoorJuspay wants to merge 2 commits intojuspay:mainfrom
ArushKapoorJuspay:feat/typescript-demo-app-clean

Conversation

@ArushKapoorJuspay
Copy link
Copy Markdown
Collaborator

Summary

Converts all 7 JavaScript source files in Hyperswitch-React-Demo-App/ to TypeScript with strict mode enabled and 0 type errors.

Changes

Config Files (created)

  • tsconfig.json — strict mode, moduleResolution: "bundler", jsx: "react-jsx"
  • src/globals.d.ts — webpack DefinePlugin globals (ENDPOINT, SCRIPT_SRC, SELF_SERVER_URL, SDK_VERSION), Window.Hyper augmentation, asset module declarations, local ambient type declarations for @juspay-tech/hyper-js and @juspay-tech/react-hyper-js

Build Tooling (modified)

  • webpack.common.js — added @babel/preset-typescript to babel presets, .ts/.tsx to resolve extensions, updated entry from index.js to index.tsx
  • package.json — added typescript, @types/react, @types/react-dom, @babel/preset-typescript to devDependencies

Source Files (renamed + typed)

Before After Key Type Additions
index.js index.tsx Non-null assertion on getElementById
App.js App.tsx Extension rename only
Payment.js Payment.tsx Promise<HyperInstance> | null state, string | null error
CheckoutForm.js CheckoutForm.tsx React.FormEvent<HTMLFormElement>, typed catch clause
Completion.js Completion.tsx Extension rename only
Cart.js Cart.tsx CartItem interface
utils.js utils.ts All function signatures, React.Dispatch types, PaymentStatusMessages

Why Local Ambient Declarations?

The demo app's node_modules contains the published @juspay-tech/hyper-js and @juspay-tech/react-hyper-js packages which don't have types fields yet. Local ambient declarations in globals.d.ts provide the type subset used by the demo app. Once the companion PRs ship, these can be removed in favor of the real .d.ts files.

Testing

cd Hyperswitch-React-Demo-App
npx tsc --noEmit  # 0 errors with strict mode

Related PRs

- Rename all 7 source files from .js to .tsx/.ts
- Add tsconfig.json with strict mode and moduleResolution: bundler
- Add globals.d.ts for webpack DefinePlugin globals and asset modules
- Add local ambient type declarations for @juspay-tech/hyper-js and
  @juspay-tech/react-hyper-js (subset used by demo app)
- Update webpack.common.js: add @babel/preset-typescript, .ts/.tsx extensions
- Add proper type annotations: component props, state, event handlers,
  async function signatures, CartItem interface
- All 0 tsc --noEmit errors with strict mode enabled
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Apr 6, 2026

…Instance, remove index signatures, add TODO for temporary ambient declarations
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