You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
@matthewrobertson thank you for the suggestion! I agree this is quite nice. While I feel pretty strong about my Node.js chops, please forgive my relative inexperience with TypeScript. (This project was converted to TS at the request of the community)
I just dropped a PR that should do what you want. IIUC this would not be a breaking change from our mishmash type union. Can you please confirm that, and whether the PR accomplishes your aims.
Activity
feat: use generic type for CloudEvent data
lance commentedon Nov 20, 2021
@matthewrobertson thank you for the suggestion! I agree this is quite nice. While I feel pretty strong about my Node.js chops, please forgive my relative inexperience with TypeScript. (This project was converted to TS at the request of the community)
I just dropped a PR that should do what you want. IIUC this would not be a breaking change from our mishmash type union. Can you please confirm that, and whether the PR accomplishes your aims.
#446
feat: use generic type for CloudEvent data (#446)