typescript-is icon indicating copy to clipboard operation
typescript-is copied to clipboard

Type protecter

Open rhalaly opened this issue 4 years ago • 1 comments

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' }

rhalaly avatar Oct 14 '20 19:10 rhalaly

+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.)

dko-slapdash avatar Dec 11 '20 09:12 dko-slapdash