Giter VIP home page Giter VIP logo

Comments (6)

eranhirsch avatar eranhirsch commented on June 11, 2024 1

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.

dartess avatar dartess commented on June 11, 2024 1

@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.

eranhirsch avatar eranhirsch commented on June 11, 2024

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.

https://www.typescriptlang.org/play?#code/C4TwDgpgBAsiBKEDGB7ATgEygXigbygG0BpKASwDsoBnYNSgcwF0AuKAIgwFcBbHkdlAC+AbgBQoSLBABJChggAPCFlwFCAawgg2tehWZtOvfoNFiJ4aGmToMxbdRxQtIFADNpiVJnEB6PygggD0AfkspSgVFBxAnXFcPaTlolX9AkPCgA

mapValues simply types the key as keyof T, it's doing what it's supposed to do here

from remeda.

dartess avatar dartess commented on June 11, 2024

Yes but it can be easily fixed in remeda via keyof T & string

from remeda.

eranhirsch avatar eranhirsch commented on June 11, 2024

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.

eranhirsch avatar eranhirsch commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.