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

Provide type definition for TypeScript #1

Open
munierujp opened this issue Nov 18, 2020 · 2 comments
Open

Provide type definition for TypeScript #1

munierujp opened this issue Nov 18, 2020 · 2 comments

Comments

@munierujp
Copy link

munierujp commented Nov 18, 2020

Could you provide type definition for TypeScript?

My idea

Add index.d.ts.

import middy from '@middy/core'

type Type = 'string' | 'int' | 'float' | 'bool'
type Config = string | [string] | [string, Type] | [string, Type, string]

export interface Options {
  names: Record<string, Config>
  cache?: boolean
  cacheExpiryInMillis?: number
  setToContext?: boolean
}

declare const env: middy.Middleware<Options, any, any>

export default env

Then, add types field to pacakge.json.

{
  "types": "index.d.ts"
}

See also

@vicary
Copy link

vicary commented Jul 21, 2021

I don't think context can be typed for middy 2.x because it is hard-coded as LambdaContext, only the request event can be typed.

I think this requires a minor update to add an option to distribute into a new event property, for example event.env, instead.

@chrisandrews7
Copy link
Owner

Please feel free to raise a PR.

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

3 participants