Skip to content
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

How to get type for a single Lambda config? #77

Open
ezmiller opened this issue Apr 1, 2023 · 2 comments
Open

How to get type for a single Lambda config? #77

ezmiller opened this issue Apr 1, 2023 · 2 comments

Comments

@ezmiller
Copy link

ezmiller commented Apr 1, 2023

Let’s say I have code like this in serverless.ts:

import { AWS } from '@serverless/typescript'
import app from '@functions/app` // this is a js/typescript lambda config blob
const sererlessConfig: AWS = {
  ...
  functions: { app },
  ...
}

Now let’s say I want to do some processing on that app import, for example to inject some environment variables. So I create a function injectEnv that takes a lambda config blob and adds the necessary environment property. The function looks like: const injectEnv = (lambdaConfig) => {…} .

Typescript will want me to type the lambdaConfig argument, since it won't like it to have an implicit any. But how can I do that? @serverless/typescript does not seem to have a type corresponding to the lambda config block.

I can get the whole functions block of the total configuration by doing AWS['functions'], but is there a way to get just the type of the lambda config block?

@lurdharry
Copy link

Import Type
import type { AWS } from "@serverless/typescript";

Use type here:
const config: AWS["functions"][number] = { handler: '${handlerPath(__dirname)}/handler.main', events: [ ], };

@ezmiller
Copy link
Author

@lurdharry thank you for the response. I'm not sure I understand what number refers to in your example line:

const config: AWS["functions"][number] = { handler: '${handlerPath(__dirname)}/handler.main', events: [ ], };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants