Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SelfDescribingJson type #1203

Open
greg-el opened this issue Jun 12, 2023 · 0 comments
Open

Improve SelfDescribingJson type #1203

greg-el opened this issue Jun 12, 2023 · 0 comments
Labels
type:enhancement New features or improvements to existing features.
Milestone

Comments

@greg-el
Copy link
Contributor

greg-el commented Jun 12, 2023

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.

@greg-el greg-el added the type:defect Bugs or weaknesses. The issue has to contain steps to reproduce. label Jun 12, 2023
@greg-el greg-el added this to the Version 4.0.0 milestone Jun 12, 2023
@greg-el greg-el added type:enhancement New features or improvements to existing features. and removed type:defect Bugs or weaknesses. The issue has to contain steps to reproduce. labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New features or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

1 participant