Comments (6)
Looking at this again, I think you might be right! The key could be string | number
but that just because you can use a number to index into the object. The mapper itself uses Object.keys() which only returns string keys...
I don't mind reviewing a PR to fix this!
Sorry for the misleading first answer again!
from remeda.
@eranhirsch i got an error with ${keyof T}
. But ${Exclude<keyof T, symbol>}
looks working and better than keyof T & string
. I, too, will think a little more and experiment, after which I will do a PR.
from remeda.
A record would be flattened as { [K in string]: T }
for your example, { [key: string]: T }
is a different object. This isn't related to remeda, I don't know why keyof
for an indexed object returns string | number
.
mapValues simply types the key as keyof T
, it's doing what it's supposed to do here
from remeda.
Yes but it can be easily fixed in remeda via keyof T & string
from remeda.
I don't know why it's being typed as number, but it means that typescript thinks the key could be a number too, and if anyone is relying on this being the case we would break their assumption and code. If the type should be just string
typescript would have inferred that.
from remeda.
So thinking about this some more, it feels like the type for the key should be
`${keyof T}`
It would cover a type like { [index: number]: unknown }
properly.
@dartess, wdyt?
from remeda.
Related Issues (20)
- Allow `conditional.defaultCase` to infer its return type HOT 3
- Incorrect type assertion for isIncludedIn HOT 5
- Add optional `obj` parameter to `Evolver`? HOT 4
- Add `invariant` HOT 2
- Add `some` and `every`? HOT 16
- [Feature Request]: Support Maps in isDeepEqual HOT 6
- Add `sortedUniq` HOT 6
- Further improve `stringToPath` types; consolidate `setPath` and `pathOr`? HOT 5
- isDeepEqual and negation in guard can break type HOT 6
- Typing issue when using `isDeepEqual` in `differenceWith` function HOT 2
- Why is fromKeys typed with Partial<>? HOT 3
- `groupBy` has broken types HOT 3
- Test against Typescript nightlies HOT 2
- [Feature Request] Remeda ESLint Plugin HOT 7
- Add mergeAndConcat function HOT 1
- add mapEntries function HOT 6
- Add "R" or "Remeda" globally to the docs website for easy experiments HOT 4
- Add `mapAccum` HOT 5
- Unexpected types when using isNullish/isNonNullish in conditional HOT 2
- Incorrect type assertion in negative case for hasSubObject HOT 1
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 remeda.