Comments (5)
Whoa, that's awesome, thank you! 😄 It evidently did better than my threads on path
there...
I think I can make versions out of that for different path lengths; that should help.
As it stands it appears unable to deal with navigation of arrays though, as [K1 in A]
notation apparently demands strings. I may want to ask them for ideas on that...
from npm-ramda.
Thanks! I've now tried to use these in assoc
, dissoc
, map
, mapObjIndexed
, pick
, pluck
, project
, prop
, propIs
, propEq
, propOr
, propSatisfies
, and a failed/WIP attempt at path
. I've been talking to donnut and blakeembrey, and hopefully we'll manage an NPM release soon.
Now lenses are a bit tough. Since you brought them up, I tried to expand on typings there, but I'm not sure yet how I can use keyof
there, and I'm open to input there. The issue pertains order of generics/information, and this is one of the great general challenges in typescript-ramda
. Let's say we wanted to type a lens such as to make use of this:
interface KeyLens<K extends keyof T> {
<T extends Struct<any>>(obj: T): T[K]; // get
<T extends Struct<any>>set(v: T[K], obj: T): T;
// <T extends Struct<any>>map(fn: (v: T[K]) => T[K], obj: T): T
}
The main issue here is of course, such a lens is actually generic, in the sense it's agnostic toward the actual data structure it might be applied to. We'd like to be able to define such a lens just by the key it navigates to, but if we wish to apply keyof
there, we run into a problem: the object structure T
is not defined yet at this point.
Alternatively, we can add this T in the interface generics already, before K
, and hope TS will take our word for the fact this will hold for any given T
.
I made a PoC for this, but unfortunately, TS doesn't appear to like this reasoning. I tries to evaluate things instead of lazily keeping our options open, and as a result, ends up discarding this option entirely.
There might be a way to improve on that, but I'm not sure if it could work in the current state of TS.
I'll close for the moment as I think I've handled anything actionable as of now. This doesn't mean I'm not looking for further suggestions to improve here though -- to the contrary!
from npm-ramda.
@tycho01
This is how path
can be typed: microsoft/TypeScript#12290
from npm-ramda.
Hello :)
I'm clearly struggling understanding this new syntax...
Example:
import R from "ramda";
interface Car {
wheels: number;
doors: number;
};
type carKeys = keyof Car;
interface FakeCar {
wheels: number;
};
type fakeCarKeys = keyof FakeCar;
const car: Car = { wheels: 4, doors: 5 };
const fakeCar: FakeCar = R.pick<Car, fakeCarKeys>(["wheels"], car);
console.log(fakeCar);
This get's me:
error TS2536: Type '0' cannot be used to index type 'T'
What should I use as the second parameter of <,>
(if type inference is failing me)?
EDIT: nevermind, the problem is not on my code, but here. A bug?
from npm-ramda.
Hey, this appears to be the regression described in #129. I haven't had the time to test their fix though... if the new nightly works we can just update it.
from npm-ramda.
Related Issues (20)
- npm-ramda motivation HOT 4
- R.Path - Typescript error for an array of objects
- `prop` does not work with optional keys HOT 1
- curry type
- `pipeWith` is missing
- Using groupBy with path always fails typecheck
- mergeDeepRight returns incompatible if objects contain array props HOT 1
- Add dissoc(prop: number)
- `transduce` and `into` are declared with `any` and for narrow use cases in general
- R.evolve is not deriving type from curried evolver
- Generics lost on currying for higher-order functions HOT 1
- type into in typescript
- How should we type lift?
- How to type pathOr?
- Expected 0 arguments, but got 1 HOT 3
- Evolve typings
- Typescript 4: Solve a lot of our problems
- Ramda 0.27 HOT 1
- Arity limitation for R.compose's rightmost function?
- Adding support for type guards to `partition` function.
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 npm-ramda.