Skip to content

Make datastore generics use lookup type #1

Closed
vidartf wants to merge 4 commits intosaulshanabrook:type-datastore-getfrom
vidartf:type-datastore-get
Closed

Make datastore generics use lookup type #1
vidartf wants to merge 4 commits intosaulshanabrook:type-datastore-getfrom
vidartf:type-datastore-get

Conversation

@vidartf
Copy link
Copy Markdown

@vidartf vidartf commented Aug 27, 2019

Alternative to consider.

Only the type system uses this internally, for end users there should be no negative effect. A positive effect is better typing in change events.
3.4.5 seems to be minimal supported version with the code as is. It is possible that a lower version could be supported with some clever casting, but no tests done.
@vidartf
Copy link
Copy Markdown
Author

vidartf commented Aug 27, 2019

Note: I don't think that the "precompute" of the schema map as a generic arg is completely necessary (but it might be, not sure). I didn't try it out too much because I thought it was nicer to not have [number] all over 😄 Open for arguments the other way if they are good ;)

@vidartf
Copy link
Copy Markdown
Author

vidartf commented Aug 27, 2019

CI failure is because docs build are still using 3.x of phosphor and these changes require 3.4 at least.

@saulshanabrook
Copy link
Copy Markdown
Owner

@vidartf could you give an example where this gives better type analysis than the original PR?

// for change events:
const data = change.change['test-schema-1']!['my-record']!;
expect(data.visible!.previous).to.equal(false);
expect(data.visible!.current).to.equal(true);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saulshanabrook This bit! Without the typings for the change/patch structures I get errors like this:

Property 'visible' does not exist on type:
Change<
  TestSchema | {
    id: "test-schema-2";
    fields: {
      enabled: RegisterField<boolean>;
      count: RegisterField<number>;
      keywords: ListField<string>;
    };
  }
>

In other words, the change.change['test-schema-1'] line isn't able to narrow it to Change<TestSchema>. Note that the test here was improved a bit to highlight this issue (the two schemas now have different types).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great! Thank you.

That makes sense, so we have to tie the ID on the change to the schema.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vidartf vidartf closed this May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants