Skip to content

fix: enforce strict generic return type for get() method#45

Merged
tduyng merged 1 commit into
ekino:masterfrom
aurelienbouteiller-ekino:fix-get-method-types
Jul 10, 2026
Merged

fix: enforce strict generic return type for get() method#45
tduyng merged 1 commit into
ekino:masterfrom
aurelienbouteiller-ekino:fix-get-method-types

Conversation

@aurelienbouteiller-ekino

Copy link
Copy Markdown

What does this PR do?
This PR fixes an issue where config.get() was unnecessarily returning T | unknown instead of strictly returning the provided generic type T. This union type forced developers to manually cast types, bypassing the main benefit of the generic parameter.

Changes:
Updated src/index.ts so get() defaults its generic to unknown and strictly returns T.
Added function overloads to getValue() in src/utils/index.ts. It now explicitly returns T when the path argument is a string, while keeping T | undefined for array/undefined paths.
Added compile-time unit tests in test/index.test.ts using vitest's expectTypeOf to assert that config.get properly maps to the expected strict type without falling back to unknown.

Related Issue: Closes #44

Comment thread src/utils/index.ts Outdated
Comment thread src/index.ts
@tduyng

tduyng commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The linter is failed!

@aurelienbouteiller-ekino

Copy link
Copy Markdown
Author

The linter is failed!

Fixed!

@tduyng

tduyng commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The linter is failed!

Fixed!

LGTM. I'll merge this PR and make a new release. Thank you @aurelienbouteiller-ekino

@tduyng tduyng merged commit 4551319 into ekino:master Jul 10, 2026
4 checks passed
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.

[Bug]: config.get<T>() return type is unnecessarily unioned with unknown

2 participants