0

for the following function (see also http://ramdajs.com/docs/#where)

var spec2 = {x: function(val, obj) { return  val + obj.y > 10; }};
R.where(spec2, {x: 2, y: 7}); //=> false
R.where(spec2, {x: 3, y: 8}); //=> true

I would like to create the typing for the case where the object T has the value of a predicate.

I was thinking I would do something like this:

    where<T>(spec: {item: (val: any, testObj: T) => boolean}, testObj: T): boolean;

but I'm not sure what to do for the key.

2 Answers 2

2

There isn't a way to represent this in the TypeScript type system.

Sign up to request clarification or add additional context in comments.

Comments

0

This seems to get closer to a solution which is partially type safe:

interface Pred2<T> {
    (x: any, y: T): boolean
}
interface ObjPred2<T> {
    [index: string]: Pred2<T>;
}
where<T>(spec: ObjPred2<T>, testObj: T): boolean;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.