combine function for property
PalmZE opened this issue · 5 comments
PalmZE commented
@raveclassic, hi!
Looks like typescript is finally ready to express combine function using tuple types:
type PropertyValue<A> = A extends Property<infer U> ? U : never;
type MapPropsToValues<PS extends [Property<unknown>, ...Property<unknown>[]]> = {
[K in keyof PS]: PropertyValue<PS[K]>;
};
function combine<PS extends [Property<unknown>, ...Property<unknown>[]], B>(
...args: [...PS, (...values: MapPropsToValues<PS>) => B]
): Property<B>;
Correctly inferred types:
const p1 = constProperty(1);
const p2 = constProperty('');
const p3 = constProperty(true);
const p4 = constProperty(new Date());
const pr = combine(p1, p2, p3, p4, (v1, v2, v3, v4) => {
return { name: 'Bar' };
});
Would you accept a PR that adds combine
to property
API?
raveclassic commented
@PalmZE Sure, feel free to do that 🎉
raveclassic commented
Hey @PalmZE , I've just pushed 1.0.0.alpha
to master, it contains the combine
combinator.
However the structure of the packages/API has changed.
Would you be interested in opening another PR to the 0.x.x
branch?
PalmZE commented
@raveclassic sorry for the delay. Is PR to 0.x.x
still relevant?
raveclassic commented
@PalmZE not sure, only if you still use it
PalmZE commented
Honestly, I'd rather use 1.x.x
version the next time, closing this one.