You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong function type when mixing default initialized parameters with regular parameters #11900
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. "
changed the title [-]Wrong function signature in VS Code when mixing default initialized parameters with regular parameters[/-][+]Wrong function type when mixing default initialized parameters with regular parameters[/+]on Nov 3, 2016
Adel KARZAZI (@akarzazi) Inside the function would still be T, while the call signature is T | undefined as it has a default initialiser (the default value is used when the argument is undefined).
Activity
mhegazy commentedon Oct 27, 2016
Optional parameters can not appear before required ones. so
nomeit is not optional. it just has a default parameter.luisabreu commentedon Oct 28, 2016
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.
mhegazy commentedon Oct 28, 2016
Defaults do not show in signature anywhere else, they are considered function implementation detail.;so I am not sure I understand the request here.
RyanCavanaugh commentedon Oct 28, 2016
Mohamed Hegazy (@mhegazy) I think when a default exists, we should be pushing
| undefinedinto the parameter typemhegazy commentedon Oct 28, 2016
is
--strictNullCheckson?mhegazy commentedon Oct 28, 2016
With
--strictNullCheckyes it should beT | undefined.luisabreu commentedon Oct 29, 2016
Yep, strict null check is on.
[-]Wrong function signature in VS Code when mixing default initialized parameters with regular parameters[/-][+]Wrong function type when mixing default initialized parameters with regular parameters[/+]sandersn commentedon Nov 3, 2016
Fix is up at #12033
akarzazi commentedon Dec 7, 2016
If default initialized parameter is automatically converted to
T | undefined.How can you enforce
Tas type ?blakeembrey commentedon Dec 7, 2016
Adel KARZAZI (@akarzazi) Inside the function would still be
T, while the call signature isT | undefinedas it has a default initialiser (the default value is used when the argument isundefined).