Skip to content

feat: Add TypeScript types for abstract store providers#1395

Merged
JamieMagee merged 1 commit intomasterfrom
jamiemagee/typescript-batch2-provider-infrastructure
Jan 17, 2026
Merged

feat: Add TypeScript types for abstract store providers#1395
JamieMagee merged 1 commit intomasterfrom
jamiemagee/typescript-batch2-provider-infrastructure

Conversation

@JamieMagee
Copy link
Copy Markdown
Contributor

@JamieMagee JamieMagee commented Jan 14, 2026

Summary

This PR continues the TypeScript migration by adding type definitions for the provider infrastructure and abstract store base classes. This required several JavaScript code changes and workarounds to satisfy TypeScript's type checker.

JavaScript Code Changes

abstractFileStore.js

  • Buffer to string conversion: Added .toString() when parsing fs.readFile results in list(), get(), and find() methods. TypeScript's Buffer type is not directly assignable to JSON.parse() which expects a string parameter.

  • Error type casting: Cast caught errors to NodeJS.ErrnoException type to safely access the .code property (e.g., checking for 'ENOENT').

  • Schema import: Added @ts-ignore for the JSON schema import (schemas/definition-1.0) which has no type declarations.

abstractAzblobStore.js

  • Azure error handling: Cast caught errors to {statusCode?: number} to safely access the .statusCode property for Azure-specific error handling.

  • Azure storage promisify: Added @ts-ignore comments for azure-storage promisify calls. The azure-storage library's callback signatures expect 4 arguments instead of the standard 3-argument signature that Node's promisify expects.

abstractMongoDefinitionStore.js

  • parseInt type safety: Wrapped score parameters with String() before parseInt() calls in buildQuery(). TypeScript correctly identifies that these parameters could already be numbers, making direct parseInt() calls invalid.

  • Error message access: Cast the error parameter to Error in the retry handler to access .message property safely.

  • MongoDB sort compatibility: Added @ts-ignore for MongoDB sort parameter. The mongodb driver's Sort type is stricter than our Record<string, number> representation, but they are functionally equivalent at runtime.

  • Unused parameter naming: Renamed unused parameters with underscore prefix (e.g., coordinates to _coordinates) per TypeScript/ESLint conventions for abstract method signatures.

providers/logging/logger.d.ts

  • Fixed the Logger type import path to correctly reference the logging module types.

@JamieMagee JamieMagee changed the title feat: Add TypeScript types for abstract store providers (Batch 2 & partial Batch 3) feat: Add TypeScript types for abstract store providers Jan 14, 2026
@JamieMagee JamieMagee requested a review from qtomlinson January 14, 2026 21:25
@JamieMagee JamieMagee force-pushed the jamiemagee/typescript-batch1-lib-types branch from 9cde083 to 90e414a Compare January 15, 2026 22:02
Copy link
Copy Markdown
Collaborator

@qtomlinson qtomlinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Base automatically changed from jamiemagee/typescript-batch1-lib-types to master January 16, 2026 23:57
…rtial Batch 3)

Add type definitions and JSDoc annotations for the provider infrastructure
and abstract store base classes as part of the ongoing TypeScript migration.

## JavaScript code changes required for type safety:

### abstractFileStore.js
- Add \`.toString()\` when parsing \`fs.readFile\` results in \`list()\`, \`get()\`,
  and \`find()\` methods. TypeScript's Buffer type is not directly assignable
  to \`JSON.parse()\` which expects a string parameter.
- Cast caught errors to \`NodeJS.ErrnoException\` type to safely access the
  \`.code\` property (e.g., checking for 'ENOENT').
- Add \`@ts-ignore\` for the JSON schema import which has no type declarations.

### abstractAzblobStore.js
- Cast caught errors to \`{statusCode?: number}\` to safely access the
  \`.statusCode\` property for Azure error handling.
- Add \`@ts-ignore\` comments for azure-storage \`promisify\` calls which expect
  4 arguments instead of the standard 3-argument signature.

### abstractMongoDefinitionStore.js
- Wrap score parameters with \`String()\` before \`parseInt()\` calls in
  \`buildQuery()\`. TypeScript correctly identifies that these parameters
  could already be numbers, making direct \`parseInt()\` calls invalid.
- Cast the \`error\` parameter to \`Error\` in the retry handler to access
  \`.message\` property safely.
- Add \`@ts-ignore\` for MongoDB \`sort\` parameter - the mongodb driver's
  \`Sort\` type is stricter than our \`Record<string, number>\` representation,
  but they are functionally equivalent.
- Rename unused parameters with underscore prefix (e.g., \`coordinates\` to
  \`_coordinates\`) per TypeScript/ESLint conventions for abstract methods.

## Files added
- providers/index.d.ts
- providers/stores/abstractFileStore.d.ts
- providers/stores/abstractAzblobStore.d.ts
- providers/stores/abstractMongoDefinitionStore.d.ts

## Files modified
- providers/logging/logger.d.ts (fixed Logger type import)
- tsconfig.json (added new files to include list)
@JamieMagee JamieMagee force-pushed the jamiemagee/typescript-batch2-provider-infrastructure branch from 7bb32bb to d333af8 Compare January 17, 2026 00:01
@JamieMagee JamieMagee merged commit c36d7b1 into master Jan 17, 2026
4 checks passed
@JamieMagee JamieMagee deleted the jamiemagee/typescript-batch2-provider-infrastructure branch January 17, 2026 00:05
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.

2 participants