deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

validation of literal types not working

Open i-am-ian opened this issue 1 year ago • 1 comments

I came across the following issue using deepkit/type 1.0.1-alpha.151:

type MyType = 'StringLiteral';
class MyClass {
    myProperty!: MyType
}
const myObject = {
    myProperty: 'NotMyType'
};
const value = cast<MyClass>(myObject);

I would expect cast to throw a ValidationError because 'NotMyType' is not compatible with the type MyType. Instead, no error is thrown and value.myProperty has the value StringLiteral. Using options of { loosely: false } does not change the behavior.

i-am-ian avatar Jun 21 '24 21:06 i-am-ian