fix: allow aliases with explicit func type annotations#135
Open
nickita-khylkouski wants to merge 2 commits intobloomberg:mainfrom
Open
fix: allow aliases with explicit func type annotations#135nickita-khylkouski wants to merge 2 commits intobloomberg:mainfrom
nickita-khylkouski wants to merge 2 commits intobloomberg:mainfrom
Conversation
Fixes bloomberg#91 When using buildCommand with an explicit type annotation on the func parameter, the type system could not infer FLAGS from the parameters, causing keyof FLAGS to be never. This made aliases impossible to use since Aliases<never> only accepts undefined. The fix changes TypedCommandFlagParameters to use Aliases<string> when keyof FLAGS is never, allowing any string as an alias target. Invalid alias targets are still caught at runtime by the existing validation in resolveAliases. This is a necessary trade-off due to TypeScript's type inference limitations when explicit type annotations are used on function parameters. Signed-off-by: Nickita Khylkouski <90287684+nickita-khylkouski@users.noreply.github.com>
afbd161 to
41c84fd
Compare
Signed-off-by: Nickita Khylkouski <90287684+nickita-khylkouski@users.noreply.github.com>
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.
Summary
Fixes #91 - Type error when adding aliases with explicit
functype annotations.Problem
When using
buildCommandwith an explicit type annotation on thefuncparameter:Root Cause
When
funchas an explicit type annotation, TypeScript'sNoInferwrapper prevents type inference from flowing toparameters. This causeskeyof FLAGSto becomenever, which makesAliases<never>- a type that only acceptsundefined.Solution
Modified
TypedCommandFlagParametersto useAliases<string>whenkeyof FLAGSisnever:Aliases<keyof FLAGS>)Aliases<string>with runtime validationChanges
packages/core/src/parameter/types.ts- ModifiedTypedCommandFlagParametersconditional typepackages/core/tests/type-inference.spec.ts- Added 4 type-level tests (positive, negative, edge case)packages/core/tests/alias-runtime.spec.ts- Added 30 runtime tests for alias validationTrade-off
This is a necessary trade-off due to TypeScript's type inference limitations:
keyof FLAGSisneverresolveAliasesTest Results