contracts.js
contracts.js copied to clipboard
interop with unique structures like immutable.js
I am curious what thoughts you have about supporting something like immutable.js where the structural typing would make sense to the user but technically fail because contracts.js would not know how to work with immutable.js objects.
It would be useful if we could teach contracts.js new tricks.
So I haven't used immutable.js too much yet but this should just be a contract on the get/set interface right?
import @ from "contracts.js"
var Immutable = require('immutable');
@ let NumMap = {
get: (Str) -> Num,
set: (Str, Num) -> NumMap
}
@ () -> NumMap
function makeMap() {
return Immutable.Map({
a:"foo"
});
}
var map = makeMap();
// contract violation because "foo" is a string
console.log(map.get("a"));
I think this at least gets the basics working. We might like some sweeter syntax though:
@ () -> Map Str => Num
function makeMap() {
return Immutable.Map({
"a": 1,
"b": 2
});
}
So perhaps we need a nice way to register new syntax?
Some sort of extensible system would be great. I mean, at some point this gets type-y but maybe there is a light-weight way to create definitions. Unfortunately doubt I'll have time to contribute thoughts to this any time soon but will keep my eye on this project. Feel free to close!