fix(types): Improve TypeScript Type Inference#5
Merged
Conversation
There was a problem hiding this comment.
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>forRecord<never, never>to represent an empty endpoint map - Narrow template literal types for endpoint keys and simplify the
requestsignature - 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
TypeFetcherclass and enhancing the clarity of console logging.TypeScript Type Safety Improvements:
src/client.ts: Updated the default type parameter ofTypeFetcherfromRecord<string, never>toRecord<never, never>to better reflect an empty record.src/client.ts: Refined the type ofkeyin theaddEndpointmethod to explicitly use the template literal type${Method} ${Path}for improved type inference.src/client.ts: Adjusted therequestmethod to simplify the key constraint fromstring & keyof Ttokeyof T, aligning with the actual usage and improving readability.Node.js Example Logging Adjustment:
examples/nodejs-usage.ts: Updated the logging statement ingetUsersto use a type assertion (as any) forresponse.datato avoid potential TypeScript errors.