Comments (2)
Great catch! Symbols() are inherently non-enumerable. Do you have a solution in mind? If not I can look into fixing
from types.
While looking into this, I found out it's worse than just symbols. The current typing for toPairs
includes any non-enumerable property in its output, including class methods!
Check out this simple instance of a class put through R.toPairs
Now let's put the same code into typescript/play
Simplified here, you get this
import * as R from 'ramda';
class Point {
public x: number;
public y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
map(fn: (a: number) => number) {
return new Point(fn(this.x), fn(this.y));
}
}
const point = new Point(3, 2);
const asPairs = R.toPairs(point);
// ^? ["x", number] | ["y", number] | ["map", (fn: (a: number) => number) => Point]
// but the value you get is `[["x", 3], ["y", 4]]`
What this means is we can never use keyof
to determine what should be part of the output array of key/value pairs
Because you also would have map
if you use a function to create and object literal:
const makePoint = (x, y) => ({
x,
y,
map: fn => makePoint(fn(x), fn(y))
});
const point2 = makePoint(3, 2);
const asPairs2 = R.toPairs(point2);
// ^? ["x", number] | ["y", number] | ["map", (fn: (a: number) => number) => Point]
// but the value you get is `[["x", 3], ["y", 4], ["map", null]]`
I've always thought that the way Object.entires was typed was just due to very old typescript, before it had the ability to be more specific
entries<T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][];
But I understand now that it's due to how keyof
does not descriminate against non-enumerables and non-own-properties
I'm thinking that the types for toPairs
and fromPairs
just needs to be typed exactly like Object.entries
and Object.fromEntries
, respectively.
Same with Object.keys
and R.keys
, Object.values
and R.values
, etc
Shitty thing is this is going to be a breaking change
from types.
Related Issues (20)
- `filter` chooses wrong type overload when used with `map`. HOT 2
- @types/ramda failing under 5.4 HOT 3
- [0.29.9] `pluck` inside `pipe` get ts error HOT 2
- Real world usage of omit is now awkward HOT 6
- 'Placeholder' is not assignable to parameter of type 'string | ((match: string, ...args: readonly any[]) => string)' in replace HOT 3
- `curry` no longer works with `map` HOT 2
- forEach requires type parameter HOT 2
- `groupBy` partial object creates issues with downstream usage. HOT 2
- Export isNotEmpty types as it is now part of ramda 0.30.0 HOT 1
- 0.30.0 lensProp type-check fail HOT 1
- ramda pick type inference is not correct HOT 1
- Typescript type inferencing HOT 1
- Make `isNotNil` a type guard HOT 3
- Missing copyright notice HOT 2
- propEq type doesn't account for optional properties HOT 1
- groupBy returns a type that is not compatible with Object.entries HOT 16
- Issues with upgrading from 0.28.25 to 0.29.1 when using yarn PnP HOT 1
- pipe and useWith get ts error HOT 3
- Why is `ElementOf` so complex? 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 types.