Description
When using the new direct object style API to create a CloudEvent
in a TypeScript project, the CloudEvent
constructor requires all properties for the event to be provided.
This is what the constructor signature looks like in the generated type definition.
constructor({ id, source, type, dataContentType, time, subject, dataSchema, schemaURL, dataContentEncoding, data, specversion }?: {
source: string;
type: string;
id: string;
time: string;
subject: string;
dataContentType: string;
dataSchema: string;
schemaURL: string;
dataContentEncoding: string;
specversion: string;
data: any;
});
There are two things wrong with this. First of all, it shows the single properties parameter as being optional, and it indicates that each of the individual fields of this properties parameter is required. This does not happen in a pure JavaScript project because the autocompletion feature in VSCode for JS projects that also have type definitions prefers the .js
version over the .d.ts
version. In a TypeScript project, however, the VSCode autocompleter only considers the .d.ts
file.
Until a fix is in place, there may be a work around by adding some TypeScript configuration option. But I'm not sure what that is - don't have enough experience with it yet.