-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Types of optional arguments not inferred correctly #56545
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
Sounds like a duplicate of #33912. |
There are a few small things at play here, but the big thing is mainly #33912. Currently, TypeScript doesn't support annotating a function's return type with a conditional type, and relating control flow types to that return type. The other small things to note here:
|
Thank you |
🔎 Search Terms
"optional" "arguments" "inference" "generic" "narrowing" "parameters"
🕗 Version & Regression Information
(tested on latest minor version of v3, v4, and v5)
⏯ Playground Link
https://www.typescriptlang.org/play?target=99&jsx=0&ts=5.3.2#code/PTAECECcHsGsFMB2p4A8CGBbADgG3qAO4CWALgBagDG0iAJmcberqKQJ7bwDOAULwDMAroiqkmyTOwBiIsRIAUqAPwAuUIiGYARvEgBKdRy7QBoVClSkkdbqBF14A4onh1Qy0N1KQXAc1B1TR09UABvXlAo0GIzJVAAXiT7eicXN31wyOicmkRvUAAvRPNQEFAASVJQWERoQjtjeFNSpISUx2dXd3I9eAAaUG0hau9iXFZCdERSRuhQSHhSIUhkdA0tXUhsnKjygGFoR1ABaEgiXuQLYjs60aFsPGI3Hd3F5dXQACIAFU4CACCXwA3K8AL4oXDcAgRXbRA5HAinc6ES6lG5eB5PF5wqLvFZXUAAKlAACZgWUwABRDA4fCDdjQITUaYLJYE0DrBgCAR9GZsf6gXqLcG8MH8PIFRbcIS4UgARnU3l8iAC7SkslE4loCn0FJy5QqAHJ3GguGI2OQMbQCKR5roBVx3Og7Otlf5eJLqtLZaRSUFNqF1TI5NrEAoAKx6g1gH5Wuw2x08ahnRZiXDsfj8coABXQkHELAzRDOsH8liweHgEtoBWw+cLE3YAHVS+X2gpOuhfQA1FhCeBqDYhAyJAB8WSisVAnac3blfdwA8SyQcaW6mVh0Xxny+dytqq+2Qh8ChMNeO+QXd7-erUXF4t45QAEn0htAKJzFknnbdA+cAB8vB8fxBlRYgqEoDF0GqfAXWqGhIDTUhBmGao7k5OxlVoAIXRiBCmVwdxdE9WtqjQeUSnrAtiCLFs21VBR5X0Uj8nI1BSSohtaKbVtIDLRiWKzcooDgJAKzpatPVwF07BzAAeAAtCdYS9SAhDEM4Z0KdRFM3bJJWgfAADpcGgPwFEKFjQAffgmlAH4SjCTl1HlR8vVAaBsDDFgSnkgANEofjHWcBHnUhFwHId-MyBIVOyadQvCyKCDaDp1wySdt3ZT5XEIUAFMcoC1y6NwQpK9I6GsmzIWhLK8Ry5A8oK+SitAfyQuvBdb2q2ynzAcAP0oFoKB4Ah81tf5fxatqKu6MdjNAfrKkcOjBlGk5iEgApE24chCOIyanUwpbc1a0AgOCLYJ2mdwNuhPJ3ETJpf2WwqLvS0q6AW0AASheZ0CoKh4G89BtHwEtZUO5btCGoZ4HLF6TveoCOo+lHPsqsdWIKBUSi8nzcCYgAWFiPL9fHvIkFhdSAA
💻 Code
🙁 Actual behavior
Specifically in the third case, the return type was incorrectly narrowed to the wrong value.
🙂 Expected behavior
The function's return type should either be the union of the two possible return cases, or it should be narrowed based on the value of the optional argument.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: