Skip to content

Commit

Permalink
fix wrong impl on constructor pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
robturtle committed Dec 12, 2019
1 parent c01b939 commit a218083
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ export class Decoder implements ICaster {
new t.Type(
spec.className,
(input: unknown): input is InstanceType<typeof constructor> => 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,
),
);
Expand Down
24 changes: 24 additions & 0 deletions test/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDay>()(d => ({
get d() {
return d.date;
},
}));
type Day = InstanceType<typeof Day>;

dec.register({
schema: schema<IDay>(),
className: 'Day',
constructor: Day,
});

const day = dec.decode<Day>('Day', { date: '2019-11-21T20:44:23.007Z' });
if (day) {
console.log('pipe works!');
} else {
throw new Error('pipe NOT WORKING!');
}

0 comments on commit a218083

Please sign in to comment.