sanctuary-js / sanctuary-def

Run-time type system for JavaScript
MIT License
293 stars 23 forks source link

Is there a default usage that does not involves creating a def function ? #211

Closed danielo515 closed 5 years ago

danielo515 commented 6 years ago

Hello,

I just noticed that def is not part of sanctuary-def imports, you need to create it with your own env and with your desire of type-checking. Since sanctuary, by default, performs type checking on every scenario except production, I was wondering if this is extensible to sanctuary-def too.

Regards

davidchambers commented 6 years ago

Are you suggesting something like the following?

//    checkTypes :: Boolean
const checkTypes =
  typeof process === 'undefined'
  || process == null
  || process.env == null
  || process.env.NODE_ENV !== 'production';

$.def = $.create ({checkTypes, env: $.env});
danielo515 commented 6 years ago

Hello @davidchambers,

I was not suggesting anything, I was just asking about the default behavior to avoid unnecessary code like I did for sanctuary.

However, I think it may be better to target node and allow bundles decide of process should exist? Apart from that, your suggestion looks fine

davidchambers commented 6 years ago

This would be useful for people using def exclusively with built-in types; those defining their own types might still need to define their own def with a custom environment.

This proposal would undoubtedly provide a convenience in some cases. I'm just not sure it warrants an increase in the surface area of the library's API.