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

[micro-dash] Reduce typings incorrect (I think) #20

Closed
benallfree opened this issue Jan 4, 2021 · 9 comments
Closed

[micro-dash] Reduce typings incorrect (I think) #20

benallfree opened this issue Jan 4, 2021 · 9 comments

Comments

@benallfree
Copy link

key: keyof E should be key: keyof ObjectWith<E>

export declare function reduce<E>(array: ObjectWith<E> | undefined, iteratee: (accumulator: E, value: E, key: keyof ObjectWith<E>) => E): E;
export declare function reduce<E, A>(array: ObjectWith<E> | undefined, iteratee: (accumulator: A, value: E, key: keyof ObjectWith<E>) => A, accumulator: A): A;
@ersimont
Copy link
Member

ersimont commented Jan 5, 2021

Thanks you for the ticket. I'm glad the library is interesting/useful enough for you to care about its typings :)

I see what you mean, it does look like that typing is wrong. Sorry about that! keyof ObjectWith<E> is going to simplify to something like string | number. I should be able to tackle this problem later in the week.

Also, please note that this the old repo for micro-dash! I'll move this ticket over to the new repo, where the fix will happen.

@ersimont ersimont transferred this issue from simontonsoftware/micro-dash Jan 5, 2021
@ersimont ersimont changed the title Reduce typings incorrect (I think) [micro-dash] Reduce typings incorrect (I think) Jan 5, 2021
@benallfree
Copy link
Author

this the old repo for

It is? This is where npm leads :/ Sorry, where is the new one?

@ersimont
Copy link
Member

ersimont commented Jan 5, 2021

The old, deprecated package on npm is micro-dash, and this ticket was originally created over at it's repo. You'll see the deprecation notice at that link.

The new package is @s-libs/micro-dash, and it's repo is right here. You created this ticket at the old repo, and I transferred it over here to the new one.

Sorry for the confusion. I moved all my open source libraries to this monorepo to simplify my life. I moved the NPM packages to sync up their version numbers, to make it easy to see/understand which versions of all the libraries go together.

@ersimont
Copy link
Member

ersimont commented Jan 7, 2021

This should be fixed up in the next release. Thank you for the report!

@ersimont
Copy link
Member

ersimont commented Jan 7, 2021

And the fix is now generally available in release 11.2.0

@benallfree
Copy link
Author

Thank you @ersimont! Long live micro-dash.

@benallfree
Copy link
Author

keyof ObjectWith<E> is going to simplify to something like string | number

PS, in my testing it actually does much better. If TS was able to infer the key names for a given type, each object in the collection will have full intellisense in the callback (VSCode)

@ersimont
Copy link
Member

ersimont commented Jan 7, 2021

Long live micro-dash.

Haha. Thanks!

PS, in my testing it actually does much better.

I'm surprised! type ObjectWith<T> = Record<string, T>, which I would have thought would lead to this chain of simplifications:

keyof ObjectWith<E>
keyof Record<string, E>
keyof { [x: string]: E }
string

@benallfree
Copy link
Author

I'm sorry, I was mistaken.

accumulator: E, value: E is what gives full intellisense. Yes I think the type of the 3rd parameter, key, is definitely just string

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

No branches or pull requests

2 participants