How to use TypeScript with Loopback

I use Strongloop's Loopback as a REST framework and ORM. I want to use TypeScript for my business logic. However, Loopback requires some form of JavaScript to support their framework. For example:

module.exports = function(Person){ Person.greet = function(msg, cb) { cb(null, 'Greetings... ' + msg); } Person.remoteMethod( 'greet', { accepts: {arg: 'msg', type: 'string'}, returns: {arg: 'greeting', type: 'string'} } ); }; 

What is TypeScript code that will generate the above JavaScript code?

+8
javascript rest typescript loopbackjs strongloop
source share
1 answer

What is TypeScript code that will generate the above JavaScript code?

You can simply use this code as it is (JavaScript TypeScript). If you're curious about module.export , you can use the TypeScript flag --module commonjs to get it in a Typeaware type like this:

 function personMixin(Person){ Person.greet = function(msg, cb) { cb(null, 'Greetings... ' + msg); } Person.remoteMethod( 'greet', { accepts: {arg: 'msg', type: 'string'}, returns: {arg: 'greeting', type: 'string'} } ); }; export = personMixin; // NOTE! 

Here is a tutorial on TypeScript module templates: https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

+8
source share

All Articles