type In = { a: number };
type Out = { b: string };
type Err = { err: string; stack?: string };
class CustomAdapter implements IAdapter<In, Out, Err>{
build(target: In): IResult<Out, Err> {
if (typeof target.a !== 'number') return Fail({ err: 'target.a is not a number' });
return Ok({ b: target.a.toString() });
}
}
const adapter = new CustomAdapter();
Example payload
const result = adapter.build({ a: null as any });
expect(result.isFail()).toBeTruthy();
expect(result.error()).toEqual({ err: 'target.a is not a number' });
https://github.com/4lessandrodev/types-ddd/issues/282
Example implementation
Example payload