Skip to content

fix(types): Improve TypeScript Type Inference#5

Merged
mast1ff merged 2 commits into
mainfrom
fix/request-first-arg-type-interfaces
Jun 19, 2025
Merged

fix(types): Improve TypeScript Type Inference#5
mast1ff merged 2 commits into
mainfrom
fix/request-first-arg-type-interfaces

Conversation

@mast1ff

@mast1ff mast1ff commented Jun 19, 2025

Copy link
Copy Markdown
Member

This pull request includes updates to improve TypeScript type safety and minor adjustments to logging in the Node.js example. The most important changes involve refining type definitions in the TypeFetcher class and enhancing the clarity of console logging.

TypeScript Type Safety Improvements:

  • src/client.ts: Updated the default type parameter of TypeFetcher from Record<string, never> to Record<never, never> to better reflect an empty record.
  • src/client.ts: Refined the type of key in the addEndpoint method to explicitly use the template literal type ${Method} ${Path} for improved type inference.
  • src/client.ts: Adjusted the request method to simplify the key constraint from string & keyof T to keyof T, aligning with the actual usage and improving readability.

Node.js Example Logging Adjustment:

  • examples/nodejs-usage.ts: Updated the logging statement in getUsers to use a type assertion (as any) for response.data to avoid potential TypeScript errors.

@mast1ff mast1ff self-assigned this Jun 19, 2025
@mast1ff mast1ff requested a review from Copilot June 19, 2025 05:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines TypeScript type definitions in TypeFetcher to improve type inference and adjusts logging in the Node.js example to suppress a TypeScript error.

  • Swap default Record<string, never> for Record<never, never> to represent an empty endpoint map
  • Narrow template literal types for endpoint keys and simplify the request signature
  • Add an explicit cast in the example logging to avoid a type error

Reviewed Changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated 2 comments.

File Description
src/client.ts Updated default generic constraint; typed endpoint key and request.
examples/nodejs-usage.ts Cast response.data to any in the console log for TS compliance.

Comment thread examples/nodejs-usage.ts
Comment thread src/client.ts
@mast1ff mast1ff merged commit ff8fa88 into main Jun 19, 2025
2 checks passed
@mast1ff mast1ff linked an issue Jun 19, 2025 that may be closed by this pull request
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.

Type Inference Not Working for First Argument

2 participants