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

flatten (deep) #32

Open
KiaraGrouwstra opened this issue Dec 10, 2016 · 3 comments
Open

flatten (deep) #32

KiaraGrouwstra opened this issue Dec 10, 2016 · 3 comments

Comments

@KiaraGrouwstra
Copy link
Member

Hi @blakeembrey. :D

I started checking out the lodash typings looking for inspiration to improve the ramda ones. Definitely learned there! Can't say I envy all the extra lodash wrappers though, and here I thought we had it bad with currying!

So one point I'd still had trouble getting to type correctly there was flatten, for which I tried out if the lodash definition (deep case) might be of help.
I tried to test like what'd be as follows in the lodash case:

let numbers: number[] = _.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]], true);

For me (nightly TS 2.2) this wasn't quite type-checking normally yet; curious if it was functional on your side or if we're in the same boat here for now.

Just figured since we're largely typing similar functions having linked issues up might be of use. That said, there might still be some existing typings in our ramda one that might be of use in further typing lodash as well.

@blakeembrey
Copy link
Member

Hey! Note that these lodash definitions, I don't think, are very well maintained and DefinitelyTyped is likely a better place to get them right now. For that specific use-case, I think you could try https://github.com/blakeembrey/array-flatten/blob/master/array-flatten.d.ts though I'm not 100% how well that works on the latest TypeScript versions either.

@unional
Copy link
Collaborator

unional commented Dec 10, 2016

Sorry, currently I was very busy at work so don't have time updating the definitions.

Hopefully when redirect works we can consolidate the work with DT and get things going for the better. 🌷

@KiaraGrouwstra
Copy link
Member Author

Hah, quite the coincidence you already had something just like this. :)
Currently the following, based on your .d.ts there, is giving me the same issue in TS Playground (currently uses 2.1.4-insiders.20161201 -- wish it allowed easily switching versions to experiment!):

declare function flatten<T>(array: NestedArray<T>): T[];
interface NestedArray <T> {
  [index: number]: T | NestedArray<T>;
  length: number;
}
let numbers: number[] = flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]);
// Type '(number | (number | (number | (number | number[])[])[])[])[]' is not assignable to type 'number[]'.
//  Type 'number | (number | (number | (number | number[])[])[])[]' is not assignable to type 'number'.
//    Type '(number | (number | (number | number[])[])[])[]' is not assignable to type 'number'.

That said, priority here is in the order of 'super not urgent' to me. Was just wondering pretty much.

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

3 participants