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
-
I have the following method:
Problem:
I want the return type to include
course
when I passtrue
for thecourse
parameter, and to exclude it (i.e., returnundefined
) when no value is passed. However, when passingtrue | undefined
to thewith
attribute, it doesn't make thecourse
optional—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?.course
istrue
, thecourse
should be included in the returned object.options?.course
is not passed (or isundefined
), thecourse
should be excluded from the returned object.How can I ensure the return type is correctly adjusted to reflect this optional
course
property?Beta Was this translation helpful? Give feedback.
All reactions