Using Typescript
Serverless Cloud supports both Javascript and Typescript.
Enable Typescript by changing the entry point of your application to index.ts.
Add tsconfig.json to the root of your project, with this minimum configuration:
// tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node"
}
}
// index.ts
import { api } from "@serverless/cloud";
api.get("/message", async (req: any, res: any) => {
res.send({ message: "Hello Cloud!" });
});
You can write your tests in Typescript as well. To reference Jest globals in your tests, install the Jest types library:
npm i --save-dev @types/jest
