gcanti / tcomb

Type checking and DDD for JavaScript
MIT License
1.89k stars 120 forks source link

T.Struct broken with NODE_ENV="production" #322

Closed beac0n closed 6 years ago

beac0n commented 6 years ago

Version

3.2.27

Expected behaviour

var T = require('tcomb'); var TestStruct = T.struct({ test: T.String}); var x = TestStruct({test: false}) TestStruct.is(x); false

Actual behaviour

var T = require('tcomb'); var TestStruct = T.struct({ test: T.String}); var x = TestStruct({test: false}) TestStruct.is(x); true

Steps to reproduce

run the script above with NODE_ENV="production"

gcanti commented 6 years ago

@beac0n thanks for opening this issue, this is not a bug though. The following line throws in development

var x = TestStruct({test: false})

so everything comes after is not reliable and can't be used as a repro.

beac0n commented 6 years ago

@gcanti thanks for the quick answer.

How should I use tcomb for this use case in production then? Should I use tcomb in production at all? Can you provide an example on how to use it properly in a production environment?

Thanks :)

gcanti commented 6 years ago

@beac0n tcomb is a runtime type system and is supposed to be used in development and disabled in production. If you want checks in production (for example for validating input, payloads etc..) you may want tcomb-validation (also if you are using typescript, check out io-ts which is written specifically for ts).

beac0n commented 6 years ago

Thanks a lot for clearing this up. Do you mind if I create a pull request to highlighting that type validation is disabled in production?

gcanti commented 6 years ago

Sure, thanks