snowplow / snowplow/snowplow-javascript-tracker
Improve `SelfDescribingJson` type
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 590
- Forks
- 232
- Avg merge
- 2h 22m
- Merged PRs (30d)
- 3
Description
The SelfDescribingJson type in core takes a type parameter, but will not accept a type with optional properties:
type Foo = {
bar: string;
baz?: string;
};
const sdj: SelfDescribingJson<Foo> = {
schema: 'iglu:com.snowplow/foo/jsonschema/1-0-0',
data: {
bar: 'bar',
// note baz not provided
},
};
will fail with:
Type 'Foo' does not satisfy the constraint 'Record<keyof Foo, unknown>'. Property 'baz' is optional in type 'Foo' but required in type 'Record<keyof Foo, unknown>'.ts(2344)
Schemas with optional properties are very common, and providing a type to accomodate this would improve type safety wherever SelfDescribingJson is currently used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SelfDescribingJson definition around line 48 of libraries/tracker-core/src/core.ts and reproduce the issue using the optional-property Foo example. Done means a SelfDescribingJson value with baz omitted is accepted while preserving useful type safety; the payload names no test file to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100