-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Fairly new to TypeScript and was excited to start using some of the benefits I enjoy from other typed languages, but was disappointed to learn it doesn't enforce types at runtime. So I was glad to find your library, but once again frustrated when I learned the limits of TS decorators.
I'm trying to use this in a Meteor app. Meteor has the concept of methods--code that is exposed and made callable by clients--and I wanted to use typechecking to enhance security. So something like:
Meteor.methods({
addEmailAddress: function(email: string) {
// Add an email address and hope like hell you haven't been nosql-injected
}
})
But decorators don't work anywhere in that context. They can't be used before the Meteor.methods block, before the property definition, in the function definition, etc.
I don't know anything about how decorators/reflection works in TS. Would it be possible to implement something like:
Meteor.methods({
addEmailAddress: Check(function(email: string) {
})
})
and have the passed function wrapped by another that checks its actual arguments against those declared? Or is there some non-decorator way to do this now? Unfortunately, breaking this code out into classes and rebinding this would be uglier than just using Meteor's own solution, a package that checks types separately.
Thanks.