typescript-is
typescript-is copied to clipboard
Type protecter
Hi, first of all thank you for your great library!
I'm wondering if you can add another action that is not "pure assertion" but also help us to protect the objects. I'm looking for something between is
and equals
that check if the object assignable and if it is remove all the unnecessary properties from the object.
Something like:
import { assign } from 'typescript-is';
interface X {
x: string;
}
assign<X>({}); // not assignable - RETURN undefined
assign<X>({ x: 'value' }); // assignable - RETURN { x: 'value' }
assign<X>({ x: 'value', y: 'another value' }); // assignable - RETURN { x: 'value' }
+1
I also asked about the similar thing in https://github.com/woutervh-/typescript-is/issues/60 - would be really cool to have such a feature. (We currently use typescript-is very heavily, thousands of places in the code, mostly for API responses validation.)