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
{{ message }}
Repository navigation
Applying a constrained generic with type parameters as the argument type doesn't properly catch constrained fields #52309
this constrains the argument but causes any conditional typing that relies on definition being a generic to fail
Can you go into more detail? The above solution is effectively correct; there's not a way to exclude candidates from inference like you would need in order to make this to work.
Sorry for the silence here, I've been looking into the resulting conditional typing failure and haven't been able to reproduce what we're seeing in a simplified TS Playground. Applying the recommended solution appropriately applied the constraint on the required field, but caused static type test failures that I assumed were related to inference from our conditional typing.
I've since realized that the test failures we're seeing are resolved if we assign the result of DefineObject to a variable and reference that variable in the surrounding function call, rather than using DefineObject directly as the object value. Code sample below to illustrate
// This causes test failures in our inferred runtime typingDefineFunction({input_parameters: {properties: {myObject: DefineObject({type: Schema.types.object,properties: {req: {type: "string"},opt: {type: "string"}},required: ["req"],});},required: ["myObject"],},});// This does notconstMyObject=DefineObject({type: Schema.types.object,properties: {req: {type: "string"},opt: {type: "string"}},required: ["req"],});DefineFunction({input_parameters: {properties: {myObject: MyObject},required: ["anObject"],},});
I'm still working on providing a Playground example, but please let me know if this behavior is familiar to you, if I should close this issue and open a new issue when I have more details, or if a pointer to where this creates problems in our actual code base would be helpful 🙇
Activity
whzx5byb commentedon Jan 20, 2023
You should explicitly provide the constraint as a context to help infer the correct type of
Props:shapirone commentedon Jan 20, 2023
whzx5byb this constrains the argument but causes any conditional typing that relies on
definitionbeing a generic to failRyanCavanaugh commentedon Jan 26, 2023
Can you go into more detail? The above solution is effectively correct; there's not a way to exclude candidates from inference like you would need in order to make this to work.
RyanCavanaugh commentedon Feb 2, 2023
Treating as duplicate of #14829
shapirone commentedon Feb 2, 2023
Sorry for the silence here, I've been looking into the resulting conditional typing failure and haven't been able to reproduce what we're seeing in a simplified TS Playground. Applying the recommended solution appropriately applied the constraint on the
requiredfield, but caused static type test failures that I assumed were related to inference from our conditional typing.I've since realized that the test failures we're seeing are resolved if we assign the result of
DefineObjectto a variable and reference that variable in the surrounding function call, rather than usingDefineObjectdirectly as the object value. Code sample below to illustrateI'm still working on providing a Playground example, but please let me know if this behavior is familiar to you, if I should close this issue and open a new issue when I have more details, or if a pointer to where this creates problems in our actual code base would be helpful 🙇
typescript-bot commentedon Feb 4, 2023
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.