-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Typescript? #110
Comments
Try using the updated type declarations from maxmellen's PR: https://github.com/maxmellen/lambda-api/tree/strict-ts My sample import { API } from "lambda-api";
const api = require("lambda-api")() as API;
api.get("/status", async (req, res) => {
return { status: 'ok' }
});
exports.run = async (event: any, context: any) => {
return await api.run(event, context)
} Any other ideas appreciated. |
Just to elaborate the import issue, the suggested import: import API from 'lambda-api'
const api = API({}); Transpiles into: const lambda_api_1 = require("lambda-api");
const api = lambda_api_1.default({}); Which results in: module.exports.default = opts => new API(opts) I didn't start a PR for this, because it may not be the ideal solution. I also may be initialising the API wrong. |
This worked for me: handler.ts import API from 'lambda-api'
import usersApi from './api/users'
import { APIGatewayProxyHandler, APIGatewayEvent, APIGatewayProxyCallback, Context } from 'aws-lambda';
const api = API({ version: 'v0.1.0', base: 'v0' })
api.get('/users', usersApi)
const handler: APIGatewayProxyHandler = (event: APIGatewayEvent, context: Context, callback: APIGatewayProxyCallback) => {
api.run(event, context, callback)
}
export { handler } |
@jsepia what are your |
Looking at ts-lambda-api, looks like you need I've tested this myself now and it works. @jeremydaly can we add this information to the README? I also think it might be worth adding the |
Add default export to match TypeScript definition #110
Hi, do you have a sample typescript which uses lambda-api?
I'm getting a bunch of errors and just want to make sure I'm not missing anything.
The errors I am getting are like this:
Thanks
The text was updated successfully, but these errors were encountered: