Skip to content
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
3 changes: 2 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

[libs]
flow-typed
decls

[options]
esproposal.class_static_fields=enable
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
suppress_comment=\\(.\\|\n\\)*\\$ExpectError
experimental.const_params=true
experimental.const_params=true
28 changes: 28 additions & 0 deletions decls/custom-error-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @flow

// This is a partial libdef for custom-error-instance. It's filled out enough
// such that it should work for the purposes of validated. However, the
// documentation shows a potentially very complex API that might be hard to Flow
// to express to a general purpose audience such as `flow-typed`.
declare module 'custom-error-instance' {
declare class CustomError extends Error {
constructor(messageOrProps?: string | Object, properties?: Object): this;

// These properties redeclared here are specifically for working with
// validated. They allow the functions to be rewritten under Flow's eyes.
// For more information see: https://github.com/facebook/flow/issues/1517
toString: () => string;
withContext: () => Error;
message: string;
originalMessage: string;
}

declare type CustomErrorApi = (
name?: string,
parent?: CustomError,
properties?: Object,
factory?: Function,
) => Class<CustomError>;

declare export default CustomErrorApi;
}
5 changes: 3 additions & 2 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type ValidateResult<V> = {
+value: V,
};

type Refine<A, B> = (value: A, error: (message: GenericMessage) => void) => B;
// Maybe this should be Error instead of mixed?
type Refine<A, B> = (value: A, error: (message: GenericMessage) => mixed) => B;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what you think here. Error maybe?


export class Context {
parent: ?Context;
Expand Down Expand Up @@ -66,7 +67,7 @@ export class Context {
return originalMessage;
}

error(inMessage: ?GenericMessage) {
error(inMessage: ?GenericMessage): ValidationError {
let context = this;
let contextMessages = [];
do {
Expand Down