-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Wrong function type when mixing default initialized parameters with regular parameters #11900
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
Optional parameters can not appear before required ones. so |
in my example, name is not an optional parameter. It's a default initialized parameter. According to the docs: "Unlike plain optional parameters, default-initialized parameters don’t need to occur after required parameters. If a default-initialized parameter comes before a required parameter, users need to explicitly pass undefined to get the default initialized value. " https://www.typescriptlang.org/docs/handbook/functions.html The problem is that the tooltip is showing the wrong information, though the control flow is being performed correctly. |
Defaults do not show in signature anywhere else, they are considered function implementation detail.;so I am not sure I understand the request here. |
@mhegazy I think when a default exists, we should be pushing |
is |
With |
Yep, strict null check is on. |
Fix is up at #12033 |
function AddProduct(product: string, quantity = 1) {
// I think quantity should be number;
} If default initialized parameter is automatically converted to |
@akarzazi Inside the function would still be |
VS Code does not show the correct parameter types on the tooltip when you mix default initialized parameters with regular parameters. Ex.:
function test(name= "John", age: number){}
The tooltip shown when you put the mouse cursor over test says (name: string, age: number): void instead of (name?:string, age: number).
The text was updated successfully, but these errors were encountered: