The recommended language for building Node.js+Sails apps is JavaScript.
But Sails also supports using TypeScript to write your custom app code (like actions and models). You can enable this support in just a few steps:
npm install typescript ts-node --save
in your app folder.npm install @types/node --save
npm install @types/express --save
app.js
file:require('ts-node/register');
node app.js
instead of sails lift
.To get you started, here's an example of a traditional Sails controller written in Typescript, courtesy of @oshatrk:
// api/controllers/SomeController.ts
declare var sails: any;
export function hello(req:any, res:any, next: Function):any {
res.status(200).send('Hello from Typescript!');
}
To try that example out, configure a route so that its target points at SomeController.hello
, relift, and then visit the route in your browser or with a tool like Postman.