sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

fix: used with sanctuary-def environments some functions throw type errors #587

Closed rockymadden closed 5 years ago

rockymadden commented 5 years ago

When using sanctuary with checkTypes set to true and the environment set to a barebones sanctuary-def environment, some functions throw type errors with valid usage. These include, but may not be limited to:

Ref: https://repl.it/@rockymadden/break-sanctuary-flip

P.S. I acknowledge this might be a sanctuary-def bug, but observing the behavior here in sanctuary I thought I'd add here off-the-cuff.

davidchambers commented 5 years ago

Why $.env rather than S.env?

rockymadden commented 5 years ago

@davidchambers In the scenario provided, there would be no reason to do so (other than illustration of the reported issue). In a real world scenario, I might be using Fluture, custom types, types from sanctuary-def, and such in my environment.

Right now, I share the same environment between sanctuary-def and sanctuary.

davidchambers commented 5 years ago

I'm curious as to why you augment $.env rather than S.env.

Is it reasonable for Sanctuary functions to rely on types included in S.env but not in $.env?

rockymadden commented 5 years ago

Interesting. There is no specific reason I did it that way besides assuming it didn't matter. However, I do see what you are saying and some other potential benefits as well (i.e. better perf). Let me invert and touch base.

rockymadden commented 5 years ago

Yep, this did indeed do the trick. Thank you, kindly, for that tidbit.

davidchambers commented 5 years ago

You're welcome, Rocky. :)