tcomb icon indicating copy to clipboard operation
tcomb copied to clipboard

Continue validation in production env

Open andrewcharnley opened this issue 8 years ago • 3 comments

Presently there are a bunch of NODE_ENV checks which disable validation in production. As we're mostly using flow rather than tcomb specific checks this appears to be doing much the same as stripping the flow out. If some checking continues but is watered down for performance reasons we may not catch the logic switch upon production, and no documentation exists to explain it. We'd rather the logic was environment agnostic, settable by config.

Although we may not always want production validation (it could be per module based) we definitely need it for function input arguments, simply to cut down on manual typeof checks, thus as a starting point we need the NODE_ENV check to be configurable. The best means to do this I believe is by a flag on the library, which can additionally be set via a new .babelrc 'tcomb' plugin flag.

andrewcharnley avatar May 02 '17 11:05 andrewcharnley

In addition this plugin flag should be an object with something like;

check: { inputs: boolean (fn args), internal: boolean output: boolean (fn return) }

andrewcharnley avatar May 02 '17 12:05 andrewcharnley

Bump. Would like to see this change as well.

rjhilgefort avatar Feb 19 '18 21:02 rjhilgefort

We should make something like a big HINT sign in the docs, because this behaviour is only documented with one small sentence and completly caught me off guard, because the behaviour only occured in production.

I ended up using tcomb-validation and this function, to reproduce the same error throwing behaviour:

import * as T from 'tcomb-validation';
const throwIfInvalidCreator = (type: T.Type) => (value: any): any => {
	const validation = T.validate(value, type);
	return validation.isValid() ? value : T.fail(validation.firstError().message);
};

beac0n avatar Jun 23 '18 22:06 beac0n