diff --git a/index.ts b/index.ts index 373d205..e8570de 100644 --- a/index.ts +++ b/index.ts @@ -310,8 +310,7 @@ export class Decoder implements ICaster { new t.Type( spec.className, (input: unknown): input is InstanceType => input instanceof constructor, - (input, context) => - either.chain(schemaCaster.validate(input, context), s => t.success(new constructor(s))), + (input, context) => t.success(new constructor(input)), t.identity, ), ); diff --git a/test/sample.ts b/test/sample.ts index a7b89ef..0afe1fe 100644 --- a/test/sample.ts +++ b/test/sample.ts @@ -532,3 +532,27 @@ test('enumSchema', 'OrderStatus', st); const st2 = 'pendding'; test('enumSchema error example', 'OrderStatus', st2, false); + +// should not use validate in pipe, should just rerun it +interface IDay { + date: Date | null; +} +const Day = extend()(d => ({ + get d() { + return d.date; + }, +})); +type Day = InstanceType; + +dec.register({ + schema: schema(), + className: 'Day', + constructor: Day, +}); + +const day = dec.decode('Day', { date: '2019-11-21T20:44:23.007Z' }); +if (day) { + console.log('pipe works!'); +} else { + throw new Error('pipe NOT WORKING!'); +}