Skip to content

The CloudEvent type should be generic #445

@matthewrobertson

Description

@matthewrobertson

As a developer I usually know what the data payload of my cloudevent will be when I get my hands on it. It would be great if I could express this in typescript to enable better type checking and auto completion:

interface MyPayload {
  foo: string;
  bar: number;
}

const myHandler = (e: CloudEvent<MyPayload>) => {
  e.data.foo; // OK
  e.data.banana; // Type Error!
};

IMO the existing type hint for the data field is not adding much value:

data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;

This would be better expressed as something like:

export interface CloudEventV1OptionalAttributes<T> {
  // ...
  data?: T;
}

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