amplitude / amplitude/Amplitude-TypeScript
Generated ampli client fails type checking for events with only optional properties
- Ngôn ngữ chính
- TypeScript
- Star
- 180
- Fork
- 68
- Merge trung bình
- 3 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 29
Mô tả
## Expected Behavior
The client generated from the `ampli` CLI should not produce any type errors for events with only optional properties with `exactOptionalPropertyTypes` on.
## Current Behavior
Events generated by `ampli` that only contain optional properties show the following TypeScript error
```
Class 'PlaceOrderButtonClicked' incorrectly implements interface 'BaseEvent'.
Types of property 'event_properties' are incompatible.
Type 'PlaceOrderButtonClickedProperties | undefined' is not assignable to type '{ [key: string]: any; }'.
Type 'undefined' is not assignable to type '{ [key: string]: any; }'.ts(2420)
```
Example generated event
```typescript
export class PlaceOrderButtonClicked implements BaseEvent {
event_type = 'Place Order Button Clicked';
constructor(
public event_properties?: PlaceOrderButtonClickedProperties,
) {
this.event_properties = event_properties;
}
}
```
## Possible Solution
The [`BaseEvent`](https://github.com/amplitude/Amplitude-TypeScript/blob/e6b19b58479cf131404047649647ce39c4835082/packages/analytics-types/src/base-event.ts#L4) class should have `event_properties` defined as `event_properties?: { [key: string]: any } | undefined;`
## Steps to Reproduce
1. Enable `exactOptionalPropertyTypes` in `tsconfig.json`.
2. Create an event with all optional properties.
3. Run `ampli pull` to generate the client
4. Run type checking with `tsc --noEmit` on the project
## Environment
- ampli Version: `@amplitude/ampli/1.31.2 linux-x64 node-v16.19.1`
- JS SDK Version: `1.9.1`
- Installation Method: yarn
- TypeScript version: `Version 4.9.3`
- tsconfig.json: https://github.com/tsconfig/bases/blob/main/bases/next-strictest.json
- Browser and Version: N/A
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.