Comments (7)
Wow this is a crazy quest you've started! (Personally, I use Ramda (it's ok/well typed))
I doubt that anyone would be able to guess the proper ouput type as it's implementation-dependent.
But you could get a wider type though that is the return type of the iteratee
as an array/list:
ReturnOf<Iteratee>[]
Where Iteratee
is the generic type of the iteratee
function that is passed to map
.
And if you get this error it means that you're either doing something too complex or what I've explained over here
from ts-toolbelt.
@pirix-gh I'm not sure I follow...
The example I presented doesn't work as a standalone so it has nothing to do with overloading of the Iteratee ...
from ts-toolbelt.
Then I am not sure of what you're doing. I never used underscore. I just saw that the docs specify the second argument but I see that you're passing an array? But I can't see this anywhere in the docs.
So I guess you're trying to do some kind of function type overload and some kind of selection?
If so, then you should write a mapped type that picks the right sub-elements. So it would map your first argument type then transform it (that's what mapped types are used for) with O.Pick
from ts-toolbelt.
The docs state vaguely (and the code backs it up) that iteratee value is actually passed to _.iteratee and then if you pass a string path array, it will be passed to _.property so my use case is valid.
But all of this has nothing to do with my problem, as the example above simply fails regardless of the other overloaded methods (which I can send here if you want)
It seems that the issue only happens because we pass an explicit array (instead of spread args)... Where in the following example it works good:
mapE<T extends object, K extends string[]>(
list: T[],
...iterator: A.Cast<K, O.PathValid<T, K>>): Array<U.Nullable<O.Path<T, K>>>;
_.map( [{arr: {arr2: [5, 1, 7]}}, {arr: {arr2: [5, 1, 7]}}], 'arr', 'arr2');
Can you tell why that happens?
from ts-toolbelt.
The following example does work with the original code (no spread).
It seems that it is related to how Typescript realizes the type of the array.
_.map( [{arr: {arr2: [5, 1, 7]}}, {arr: {arr2: [5, 1, 7]}}], ['arr', 'arr2'] as ['arr', 'arr2']);
One can try to use
_.map( [{arr: {arr2: [5, 1, 7]}}, {arr: {arr2: [5, 1, 7]}}], ['arr', 'arr2'] as const);
But then the array becomes readonly
and can't be passed into your library types...
from ts-toolbelt.
You can, use T.Writable
before passing it to other types. Sorry that I can't help you more atm. I am very busy.
from ts-toolbelt.
That works!
Writable of Tuple is not exported - I will open a bug for it.
from ts-toolbelt.
Related Issues (20)
- `Narrow` doesn't work properly on intersections with `{}` type HOT 1
- Documentation needs to have examples HOT 1
- Unreadable documentation du to contrast issues HOT 2
- U.Merge adds unexpected index signatures when applied to intersection types
- Dark theme is too hard to read code. HOT 4
- Namespace for testing related types
- Any.Compute changes empty tuple type
- String.StartsWith?
- Custom merge types
- Exact Object HOT 3
- request: retheme the documentation
- Object.Paths broken with TS 4.9 HOT 8
- O.Merge with nested objects should compute.
- OptionalDeep<any> shows an error
- Update syntax highlighting colors for docs HOT 2
- A/Any namespace doesn't export "If" type
- deprecate `Narrow` type
- `Update` doesn't work when attempting to make keys non-nullable
- Create a new docs website HOT 3
- Incorrect Optional (Patch?) results on types which look like Error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-toolbelt.