Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compartment-mapper): Needless genericity considered harmful #1026

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

kriskowal
Copy link
Member

The has utility function in the compartment mapper did not need to be generic. Because it was generic, at a vast distance down the dependency chain, TypeScript proposed bizarre combinations of types for each of the uses, probably sampling the first ambient type that emitted a valid function, then failed type check in compartment-mapper.

The has utility function in the compartment mapper did not need to be generic.  Because it was generic, at a vast distance down the dependency chain, TypeScript proposed bizarre combinations of types for each of the uses, probably sampling the first ambient type that emitted a valid function, then failed type check in compartment-mapper.
@kriskowal kriskowal requested a review from mhofman January 28, 2022 23:19
Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Fine fix, but the problem was a malformed template

@@ -45,10 +45,8 @@ const defaultCompartment = Compartment;
const q = JSON.stringify;

/**
* @template {string | number} Key
* @template Value
Copy link
Contributor

Choose a reason for hiding this comment

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

There laid your problem!

It should have been @template {any} Value

Value is a deprecated alias for AmountValue.

You should be able to keep it generic if you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

After double checking, adding a type constraint wouldn't have helped, only renaming to something that didn't conflict with a type in scope would have, e.g. TValue

@kriskowal kriskowal merged commit 77e3d91 into master Jan 28, 2022
@kriskowal kriskowal deleted the kris-unnecessary-genericity-considered-harmful branch January 28, 2022 23:48
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