Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Pass through value failure #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export type Failure = {
/**
* A key indicating the location at which validation failed.
*/
key: string;
key?: string;

/**
* The original value passed through so data inspection can be done after failure.
* value is `any` here because its argument in `validate` is `any` type.
*/
valueInvalidated: any;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/runtype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function create<A extends Runtype>(check: (x: {}) => Static<A>, A: any):
check(value);
return { success: true, value };
} catch ({ message, key }) {
return { success: false, message, key };
return { success: false, message, key, valueInvalidated: value };
}
}

Expand Down