Category Labels: frontend, sdk, typescript, type-safety, refactor
Summary: Achieve full end-to-end type safety by converting remaining JavaScript files in the frontend to TypeScript, adding strict TypeScript configuration, and sharing types between the frontend and SDK.
Background: The frontend has a tsconfig.json and the SDK (sdk/src/types.ts) defines TypeScript types. However, some frontend files may still be JavaScript (.js/.jsx) rather than TypeScript. The SDK types may need to be shared with the frontend to avoid duplication. The shared/ directory contains errorCodes.js (JavaScript, not TypeScript).
Problem Statement: Mixed JavaScript/TypeScript codebase reduces type safety. Duplicated type definitions between frontend and SDK create maintenance burden and risk of inconsistency. Full TypeScript strict mode catches bugs at compile time rather than runtime.
Objectives:
- Convert remaining
.js/.jsx files in frontend to .ts/.tsx.
- Enable
strict: true in tsconfig.json and fix resulting type errors.
- Create a
@finchippay/shared-types package or use the SDK types in the frontend.
- Convert
shared/errorCodes.js to shared/errorCodes.ts.
- Add
tsc --noEmit to CI and fail on type errors.
Scope:
- In scope: TypeScript conversion, strict mode, shared types package, CI enforcement.
- Out of scope: backend TypeScript conversion (future issue), contract Rust type generation.
Detailed Implementation Requirements:
- Audit frontend for
.js/.jsx files:
- Run
find frontend -name "*.js" -o -name "*.jsx" | grep -v node_modules | grep -v .next.
- Convert each to
.ts/.tsx with proper type annotations.
- Key files:
jest.setup.ts (already TS?), config files, utility scripts.
- Update
frontend/tsconfig.json:
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true
}
}
- Fix all new type errors incrementally.
- Create
shared/types/ package or symlink:
shared/types/index.ts — re-exports from sdk/src/types.ts.
- Frontend imports from
@finchippay/shared-types or ../../shared/types.
- Types:
Payment, Account, Analytics, Tip, Webhook, TurretDeployment, etc.
- Convert
shared/errorCodes.js → shared/errorCodes.ts:
- Add
ErrorCode type: { code: string; status: number; message: string; description?: string }.
- Export typed error code map.
- Update SDK
sdk/src/types.ts:
- Ensure all API response types are defined.
- Add JSDoc comments for each type.
- Update
frontend/lib/api.ts (or wherever API calls are):
- Add return type annotations using shared types.
- Example:
async function getAccount(pk: string): Promise<Account>.
- Update CI:
- Ensure
npm run type-check runs tsc --noEmit.
- Fail CI on type errors.
Expected Architecture:
shared/
├── errorCodes.ts (converted from .js)
└── types/
└── index.ts (NEW: shared type definitions)
frontend/
├── tsconfig.json (updated: strict mode)
└── **/*.ts[x] (converted from .js[x])
sdk/src/
└── types.ts (updated: complete types)
Acceptance Criteria:
- No
.js/.jsx files remain in frontend source (excluding config files).
strict: true enabled with zero type errors.
- Shared types eliminate duplicate type definitions.
shared/errorCodes.ts exports typed error codes.
- Frontend API functions have proper return types.
tsc --noEmit passes in CI.
- CI: Frontend type-check passes. SDK build passes.
CI Validation: This issue includes acceptance criteria that must pass CI checks in .github/workflows/ci.yml. PRs solving this issue must pass all relevant CI jobs before merging.
Summary: Achieve full end-to-end type safety by converting remaining JavaScript files in the frontend to TypeScript, adding strict TypeScript configuration, and sharing types between the frontend and SDK.
Background: The frontend has a
tsconfig.jsonand the SDK (sdk/src/types.ts) defines TypeScript types. However, some frontend files may still be JavaScript (.js/.jsx) rather than TypeScript. The SDK types may need to be shared with the frontend to avoid duplication. Theshared/directory containserrorCodes.js(JavaScript, not TypeScript).Problem Statement: Mixed JavaScript/TypeScript codebase reduces type safety. Duplicated type definitions between frontend and SDK create maintenance burden and risk of inconsistency. Full TypeScript strict mode catches bugs at compile time rather than runtime.
Objectives:
.js/.jsxfiles in frontend to.ts/.tsx.strict: trueintsconfig.jsonand fix resulting type errors.@finchippay/shared-typespackage or use the SDK types in the frontend.shared/errorCodes.jstoshared/errorCodes.ts.tsc --noEmitto CI and fail on type errors.Scope:
Detailed Implementation Requirements:
.js/.jsxfiles:find frontend -name "*.js" -o -name "*.jsx" | grep -v node_modules | grep -v .next..ts/.tsxwith proper type annotations.jest.setup.ts(already TS?), config files, utility scripts.frontend/tsconfig.json:{ "compilerOptions": { "strict": true, "noImplicitAny": true, "strictNullChecks": true, "noUncheckedIndexedAccess": true } }shared/types/package or symlink:shared/types/index.ts— re-exports fromsdk/src/types.ts.@finchippay/shared-typesor../../shared/types.Payment,Account,Analytics,Tip,Webhook,TurretDeployment, etc.shared/errorCodes.js→shared/errorCodes.ts:ErrorCodetype:{ code: string; status: number; message: string; description?: string }.sdk/src/types.ts:frontend/lib/api.ts(or wherever API calls are):async function getAccount(pk: string): Promise<Account>.npm run type-checkrunstsc --noEmit.Expected Architecture:
Acceptance Criteria:
.js/.jsxfiles remain in frontend source (excluding config files).strict: trueenabled with zero type errors.shared/errorCodes.tsexports typed error codes.tsc --noEmitpasses in CI.CI Validation: This issue includes acceptance criteria that must pass CI checks in
.github/workflows/ci.yml. PRs solving this issue must pass all relevant CI jobs before merging.