-
Notifications
You must be signed in to change notification settings - Fork 6
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
remove filter never from select and add deep filter never to fix hand… #180
Conversation
Just a few notes re deployment:
|
@angelini we won't need to rebuild everyone's client for this. just new ones being generated going forward |
@@ -52,10 +59,10 @@ export type Select<Schema, Selection extends FieldSelection | null | undefined> | |||
? Select<T, Selection>[] | |||
: Schema extends null | |||
? Select<Exclude<Schema, null>, Selection> | null | |||
: FilterNever<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove this, there is a window of time where the generated API client for an app (potentially) uses this version of api-client-core
but doesn't DeepFilterNever
the return.
I think maybe we take a different approach: what if we give the current Select
a new name, say InnerSelect
, and instead do this:
export type Select<Schema, Selection extends FieldSelection | null | undefined> = DeepFilterNever<InnerSelect<Schema, Selection>>
which doesn't require a client rebuild and would only need a minor version bump (since it's backwards compatible).
Also, since the Select
above has no constraints on the Schema
type, we either need to consider adding the extends Record<string, unknown>
constraint or making DeepFilterNever
not need it, e.g.
export type DeepFilterNever<T> = T extends Record<string, unknown>
? FilterNever<{
[Key in keyof T]:
T[Key] extends Record<string, unknown>
? DeepFilterNever<T[Key]>
: T[Key];
}>
: T
}>;
I think putting the constraint on Schema
should be fine since a schema is never a literal / array / non-object thingy.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And note, by "potentially uses", I think it would require the users to manually specify an api-client-core
that would result in a yarn install
grabbing the new version. Unlikely, but it could happen. If there's any concern there, we can double check existing package.json
s to see if this would happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thegedge that makes sense. One other thing that @airhorns brought up was that we don't yarn install
on every rebuild so even though we've updated their api-client-core
version the old version is the one that's imported until someone runs yarn install
. So I think in addition to your suggested change, I'm going to re-implement Select
in the same way in our codegen and remove it once all packages have been updated.
d234b9c
to
5efd845
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super happy this worked out! 🚀
}; | ||
|
||
/** | ||
* Filter out any keys in `T` that are mapped to `never` recursively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth expanding a bit by calling out that objects, after having their never
-valued keys filtered out, also get filtered out of their parent if they are empty. i.e.,
type A = DeepFilterNever<{ a: { b: never }, c: "test" }>;
type B = { c: "test" }; // same as A
type C = { a: {}, c: "test" }; // not this one though
Suggesting that because an empty object is distinct from never
. Worth a double check that it's doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an example in the comment and a test to make sure it's the case.
Failing tests look be a real issue. Will address |
…ling types that have circular references
e7a2579
to
66b8841
Compare
Added a test to verify that you can still select the nested circular props. Also to note is that with
DeepFilter
you can no longer pass in a schema that has an optional property. This is fine with Gadget schemas as these are typed asprop: type | null
instead ofprop?: type
We will probably want to bump a minor version for this so that this change doesn't get picked up by older client packages
cc @angelini
PR Checklist