Skip to content

Typed Custom Events #512

@tsteckenborn

Description

@tsteckenborn

Hey there,

it would be great to enhance the type safety when working with events.

Given a sample with two services (A and B), if an event is defined in service A, such as:

        event SomeService.SomeEvent : {
            ID        : SomeEntity:ID;
            }

and e.g. consumed in service B, such as:

import SomeService, {
 SomeEvent,
} from '#cds-models/SomeService';

//...

export default class SomeOtherService extends cds.ApplicationService {
 override async init() {
// ...
  const someService = await cds.connect.to(SomeService);
  someService.on(SomeEvent, async (msg) => {
   console.log(msg.data);
  });
// ...

then msg (or msg.data) or not yet typed. The properties are eventually available in the class, yet not "exposed" in that kind of usage.

Br,
Tobias

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