-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Deducing return types from boolean arguments does not work with JSDoc and default argument values #59214
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
Comments
Looking more into the other issue I found, I can see that problem number 2 can be manually fixed by stating the default value. I also tried stricter template constraint, but the error still persists: /**
* @template {true|false} [VReturnsNumber=true]
* @param {VReturnsNumber} returnsNumber
* @returns {TypeChoice<VReturnsNumber, number, string>}
*/
function returnByChoice(returnsNumber = true) {
// @ts-ignore
return null;
} The error still is:
In this case, it is clearly wrong, as there is no way |
The error is correct, because generic arguments can be provided explicitly: returnByChoice<false>() // Why is returnsNumber true, when the type can only be false? That is what is meant with
|
Effectively a duplicate of #58977 @MartinJohns you're my favorite "eager noobie" here btw 👍 (this is an inside joke, OP please disregard) |
If this is a duplicate would it make sense for me to create more specific issue regarding the workaround with |
|
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
🕗 Version & Regression Information
I don't know how to determine the exact version VSCode is using, but I just updated it...
⏯ Playground Link
https://www.typescriptlang.org/play/?jsx=0&filetype=js#code/C4TwDgpgBAKuEGEAWB7AlgYwgHhlCAHsBAHYAmAzlAEYooA2EAhiQDSwBiaAThcOzADKEDCnIA+KAF5Y+IqUpRg3AK7QA-Jx58oALljDR5ANwAoU6EhQAIiKYgAovPIVc7ABpziL2JJkwzUwB6ACoQ0ygQqAABYgBbMHomYigAb1oGZhIAXygANQAlCGAVbhIKADkVOOoIbgio6LAmbiY4tNsMeydvSmwMxhZ2QuLS8qqauvFc7lGyyura7igGmNmS+bS4SGR0LGwRjfHFuvYSE+52Pm40EgBzaYag0wAzFRIMYDQxKHWxgCEQLtMBAABR-eYTJbSJSqCAASjSESgKORKKCQRiwAoAFo0HcSChZmjfnMSFBzvR6GZsuYjDoKKgVPQyP8IFC6jCISRAcCsKDlGp4WZ6cAoIyUMzWRBBMpbncuWTeagQaCXkx6BQEWYMVAAIKfFQaqBIW7AfSi8VMll6zUoNkc7j6a7yqAAHwpF1MlolUttFHt7IuiqOyr2YOF5iAA
💻 Code
This problem occurs when trying to use JSDoc with TypeScript conditional types. The conditional type I created is the following:
Application in plain javascript:
🙁 Actual behavior
Error on the default argument:
Additionally, the type is unknown if no argument is provided.
🙂 Expected behavior
Additional information about the issue
I also tried to use this to suppress the error, but it kills the type inference in the process (the result type is always
number | string
):The text was updated successfully, but these errors were encountered: