Skip to content

Logger context type error for Cloudflare RPC DurableObjects #9

Open
@Futhark

Description

@Futhark

This library cannot be used without casting ctx as unknown as ExecutionContext or any while instantiate in latest DurableObject that extends DurableObject class:

export class TestServiceDurableObject extends DurableObject {
    private readonly logger: BaselimeLogger;

    public constructor(state: DurableObjectState, environment: Environment) {
        super(state, environment);

        this.logger = new BaselimeLogger({
            apiKey: environment[TestSecrets.baselimeApiKey],
            ctx: state,
            isLocalDev: environment.IS_LOCAL_DEV === "true",
            service: "test-service",
            namespace: "test-service-durable-object",
        });
    }

    public async sayHello(name: string): Promise<string> {
        return `Hello, ${name}!`;
    }
}

this is because DurableObjectState which is an execution context doesn't implement passThroughOnException(): void; from ExecutionContext. But I can see that you are using only waitUntil(promise: Promise<any>): void; from this type so this context type could be narrowed to use this library without type casting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions