Skip to content

Conversation

@svozza
Copy link
Contributor

@svozza svozza commented Jan 7, 2026

Issue #, if available: closes #22

I closed the pull request #18 with the following comment:

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.

However, today I spent several hours trying to debug an issue related to this namespacing problem and I have realised that my assessment above was wrong.

The reason the errors I was seeing went away was because by chance my import of InvokeStore happened to be loaded by the compiler before the aws-lambda types. I had another module that uses aws-lambda far more extensively and I had to pinpoint the exact file where aws-lambda was first loaded and put my InvokeStore import above this to make the compiler errors disappear.

Relying on import order like this is obviously a very brittle and unsatisfactory workaround so I am re-opening my closed PR with a fix that will remove these errors.

I have just copied the same description of changes from that issue so we don't have to switch between multiple issues.

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.

@svozza svozza requested a review from a team as a code owner January 7, 2026 12:47
@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 44241d8

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

@svozza svozza changed the title Namespace global fix: use global namespace when defining awslambda InvokeStore global type Jan 7, 2026
Co-authored-by: George Fu <kuhe@users.noreply.github.com>
@kuhe kuhe merged commit 8437cdc into awslabs:main Jan 8, 2026
3 checks passed
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.

var awslambda declaration conflicts with @types/aws-lambda namespace declaration (TS2300)

3 participants