snowplow / snowplow/snowplow-javascript-tracker

Improve `SelfDescribingJson` type

Open
#1,203 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.