cloudflare / cloudflare/workerd

AnalyticsEngineDataPoint.doubles should allow null values

Open
#5,889 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

## Description

Currently, the `doubles` property in `AnalyticsEngineDataPoint` is strictly typed as `number[]`. This is inconsistent with the indexes and blobs fields, which both allow null values to represent missing data in specific positions.

Since Workers Analytics Engine supports sparse arrays, the current type definition forces a friction point for TypeScript users.

## Impact

TypeScript users wishing to record sparse double fields are currently prohibited from passing arrays containing null (e.g., [0, null, 1]). To work around this, users are forced to use type casting:

```ts

// Current workaround required:
doubles: [10, null, 20] as unknown as number[]
```

## Proposed Change

Update the `doubles` property to allow `null` values within the array to align with the underlying capabilities and other property definitions.

```diff
export interface AnalyticsEngineDataPoint {
indexes?: ((ArrayBuffer | string) | null)[];
- doubles?: number[];
+ doubles?: (number | null)[];
blobs?: ((ArrayBuffer | string) | null)[];
}
```

https://github.com/cloudflare/workerd/blob/main/src/workerd/api/analytics-engine.h#L33-L49

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.