Skip to content

Conversation

@svozza
Copy link
Contributor

@svozza svozza commented Nov 18, 2025

Description of changes:

When using the new v0.2.0 version of InvokeStore I encountered the following error trying to use the global InvokeStore object:

globalThis.awslambda?.InvokeStore?.getContext()

The error:

src/LogAttributesStore.ts:92:31 - error TS2339: Property 'InvokeStore' does not exist on type 'typeof awslambda'.

92     if (globalThis.awslambda?.InvokeStore?.getContext() === undefined) {

The issue is because I am using the popular aws-lambda types package, which defines the awslambda global as a namespace:

declare global {
    namespace awslambda {
        class HttpResponseStream extends Writable {
            static from(
                writable: Writable,
                metadata: Record<string, unknown>,
            ): HttpResponseStream;
            setContentType: (contentType: string) => void;
        }
        function streamifyResponse<TEvent = any, TResult = void>(
            handler: StreamifyHandler<TEvent, TResult>,
        ): StreamifyHandler<TEvent, TResult>;
    }
}

As InvokeStore does not use a namespace, the global it defines does not get merged with the other awslambda namespace:

declare global {
    var awslambda: {
        InvokeStore?: InvokeStoreBase;
        [key: string]: unknown;
    };
}

I think the above may have been done this way to allow the InvokeStore field to be optional using the ? token. Namespaces don't support this but you can say a value can be undefined.

This PR makes the change to use a namespace instead. I have tested this with my project and the build error is resolved by this change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@svozza svozza requested a review from a team as a code owner November 18, 2025 22:13
@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

🦋 Changeset detected

Latest commit: a840984

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws/lambda-invoke-store Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@trivikr trivikr changed the title use global namespace when defining awslambda InvokeStore global type fix: use global namespace when defining awslambda InvokeStore global type Nov 19, 2025
@svozza
Copy link
Contributor Author

svozza commented Nov 20, 2025

So it turns out the issue here is not down to namespace merging but that when you only use the global instance of InvokeStore you need to add an empty import to the top of the file:

import '@aws/lambda-invoke-store';
 
export const handler = (event: unknown) => {
  globalThis.awslambda?.InvokeStore?.getContext()
  // ...
}; 

This only works if you are using v0.2.1 as the previous version did not export the types correctly for CommonJS. Closing this PR as not required.

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

Successfully merging this pull request may close these issues.

1 participant