Optional with and typesafe return #3840
ChoaibMouhrachAkera
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following method:
Problem:
I want the return type to include
coursewhen I passtruefor thecourseparameter, and to exclude it (i.e., returnundefined) when no value is passed. However, when passingtrue | undefinedto thewithattribute, it doesn't make thecourseoptional—it just sets the type totrue | undefined. This issue also affects the return type, as it doesn't reflect the optional nature ofcourse.Expected Behavior:
options?.courseistrue, thecourseshould be included in the returned object.options?.courseis not passed (or isundefined), thecourseshould be excluded from the returned object.How can I ensure the return type is correctly adjusted to reflect this optional
courseproperty?Beta Was this translation helpful? Give feedback.
All reactions