Forum Discussion
Problem using "d3-array".rollup (and it spread argument) in a Power BI Custom Visual
- 6 years ago
Hi Schizzomarino ,
Sorry, but I took a shot before trying it myself. But if I change the key attribute to ...key: any[] I can get your code working.
I do realise that the typing are a bit off now, but looks like TypeScript doesn't work correctly with this type of parameter binding.
But the most important thing: it compiles!
-JP
Thanks jppp ,
I had not noticed this... Just goes to show how I still need to learn about definitions in typescript
So looking at the type definition I found this
/*
Hi Schizzomarino ,
You can adjust your local version in the node_modules/@types/d3-array folder.
And I think you only need to add the spread '...' before the key parameter:
export function rollup<TObject, TKey, TReduce>(a: Iterable<TObject>, reduce: (value: TObject[]) => TReduce, ...key: (value: TObject) => TKey) : Map<TKey, TReduce>;
-JP
- Schizzomarino6 years agoAdvocate I
Hi jppp ,
I had tried that amongst a whole pletora of other combinations; but Visual Studio will not compile this... I get the following tooltip:
I have tried so many variations but can't find one that works; and I found this discussion on this:
https://stackoverflow.com/questions/51737041/mapping-generic-spreaded-argument-types-in-typescriptFor now I can't quite wrap my head around the technical topic in the above thread... I finsd it rather complicated, probably why it has taken two years, so far, to not have it fixed :-0
Would anyone know how to get this to work? It would be great after two years to find this solution and update the types mapping for d3-array in the git repository
Thanks again jppp for pointing me in the right direction, but before I set yours as the correct answer I want to see if anyone has code that will work to define spread arguments when exporting types definitions in Typescript
- jppp6 years agoContinued Contributor
Hi Schizzomarino ,
Sorry, but I took a shot before trying it myself. But if I change the key attribute to ...key: any[] I can get your code working.
I do realise that the typing are a bit off now, but looks like TypeScript doesn't work correctly with this type of parameter binding.
But the most important thing: it compiles!
-JP
- Schizzomarino6 years agoAdvocate I
Thanks so much jppp
That worked!If "any[]" (and "any" for that matter) will enable loose type setting but (seem to) work flawlessly, what is stopping everyone from creating such loose typescript definitions?