-
Notifications
You must be signed in to change notification settings - Fork 0
Description
right now defining a type with properties and functions, not to mention statics if i implement that, looks like
const Todo = Typesafe.defineClass({
properties: {
done: Boolean,
author: {
properties: {
name: {
properties: {
first: String,
last: String
}
},
age: Number
},
functions: {
getFullName: function() {
return this.name.first + ' ' + this.name.last;
}
}
}
},
functions: {
isDone: function() {
return this.done === true;
}
}
});
let instance = new Todo();
but its possible we could shorten this to
const Todo = Typesafe.defineClass({
complete: function() {
this.status = 'complete';
},
author: {
name: {
first: String,
last: String
},
getFullName: function() {
return this.author.name.first + ' ' + this.author.name.last;
}
age: Number
}
});
we'd have to interpret anything of type function to be on the prototype of that object level. this would definitely make the syntax easier but i think it hampers long term some of the cool things we could do with return types. For instance, we could tweak the definitions to be a little more verbose for functions like
const Todo = Typesafe.defineClass({
functions: [
{
returns: String,
defn: function() {
this.status = 'complete';
}
}
],
properties: {
author: {
properties: {
name: {
properties: {
first: String,
last: String
}
},
age: Number
}
}
}
});
by specifying the type of the return we could possibly find a way to wrap each function like a curry and verify that the return type matches. potentially even doing something like returnTypes to allow for similar things like any via [null, String] and throw exception if the type returned was different than definitions
some other options include removing the properties key and just getting all properties whose typeof is not 'function' and assuming they're the nested and doing things like statics as a keyword and always look for that