You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionpickFunc<TextendsDemoO,UextendsToSchemaType<T>>(obj: T,schema: U): PickBySchema<T,U>{throw"not yet implemented";}constres=pickFunc(post,["id","body"]);res.id;// The message "title does not exist" was successfully displayedres.title;res.body;// When using nested schema, the type constraint does not take effectconstres=pickFunc(post,["id",["tags",["name"]]]);res.id;// Expect an error messageres.title;// Expect an error messageres.tags[0].idres.tags[0].name
I created the PickBySchema type to generate attribute field constraints for the object.
It is effective when used alone.
typePickBySchema<TextendsDemoO,UextendsToSchemaType<T>>={[KinUextends(infer U1)[]
? U1extendsstring
? U1
: U1extends[infer U2,SelectSchemaType]
? U2extendsstring
? U2
: never
: never
: never]: T[K]extendsstring
? T[K]
: T[K]extends(infer O)[]
? OextendsDemoO
? PickBySchema<O,GetNestedSchema<U,K>>[]
: never
: never;};typePostOnlyId=PickBySchema<Post,["id",["tags",["id","name"]]]>;
🙁 Actual behavior
When passing nested arrays in function parameters, the return value does not get the expected type constraints
🙂 Expected behavior
When passing a one-dimensional array or a nested array as a function parameter, the return value is expected to be bound by the specified field
The text was updated successfully, but these errors were encountered:
This repro is long enough that it's unlikely to represent a bug in TypeScript. If you can provide a shorter one (5-10 lines is sufficient to reproduce almost any defect) we can investigate, but we don't have the resources to dig in to things this large.
First of all, thank you very much for your replies, and I apologize for providing a slightly longer reproduction. Since this problem was discovered during debugging nested arrays, I'll close the issue before I provide a parsimonious reproduction.
Bug Report
A function that passes in a custom schema that constrains the values of the properties of the returned object.
But when the parameters are nested arrays, the type constraint does not take effect.
🔎 Search Terms
nested array, nested tuple, type Inference, type constraints
🕗 Version & Regression Information
v4.6.4
⏯ Playground Link
Playground link with relevant code
💻 Code
I created the
PickBySchema
type to generate attribute field constraints for the object.It is effective when used alone.
🙁 Actual behavior
When passing nested arrays in function parameters, the return value does not get the expected type constraints
🙂 Expected behavior
When passing a one-dimensional array or a nested array as a function parameter, the return value is expected to be bound by the specified field
The text was updated successfully, but these errors were encountered: