serverless-examples icon indicating copy to clipboard operation
serverless-examples copied to clipboard

Improve typing for typescript-with-node serverless function example

Open eliasm307 opened this issue 2 years ago • 0 comments

This example can be improved by applying the types defined in @scaleway/serverless-functions e.g.

import type { Handler } from "@scaleway/serverless-functions/framework/types/types";

export const handle: Handler = async (event, context, cb) => {
    return {
        body: "Hello world!",
        headers: { "Content-Type": ["application/json"] },
        statusCode: 200,
    };
};

The types from @scaleway/serverless-functions/framework/types/types could also be exposed at the package entry point so it can be simplified to:

import type { Handler } from "@scaleway/serverless-functions";

export const handle: Handler = async (event, context, cb) => {
    return {
        body: "Hello world!",
        headers: { "Content-Type": ["application/json"] },
        statusCode: 200,
    };
};

eliasm307 avatar Jun 10 '23 15:06 eliasm307