Include Default Parameter Values in Signature Help
See original GitHub issueFrom https://github.com/Microsoft/vscode/issues/28925
TypeScript Version: 2.4.0
Feature Request
signatureHelp
current shows when a parameter is optional but does not include any information about that parameter’s default value:
function foo(x = 10) { }
foo(|)
Result of TSServer signatureHelp
on foo
[Trace - 5:42:22 PM] Response received: signatureHelp (378). Request took 20 ms. Success: true
Result: {
"items": [
{
"isVariadic": false,
"prefixDisplayParts": [
{
"text": "foo",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
}
],
"suffixDisplayParts": [
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"separatorDisplayParts": [
{
"text": ",",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
}
],
"parameters": [
{
"name": "x",
"documentation": [],
"displayParts": [
{
"text": "x",
"kind": "parameterName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"isOptional": true
}
],
"documentation": [],
"tags": []
}
],
"applicableSpan": {
"start": {
"line": 3,
"offset": 5
},
"end": {
"line": 3,
"offset": 5
}
},
"selectedItemIndex": 0,
"argumentIndex": 0,
"argumentCount": 0
}
When the default value is a simple literal type, it would be helpful to display this default value in the signature help. This information could be included in the displayParts
response
Issue Analytics
- State:
- Created 6 years ago
- Reactions:96
- Comments:29 (6 by maintainers)
Top Results From Across the Web
scala - Method signature for a function with default values
In Scala, is there a way to specify that a function should have default parameter values declared? For example, in the code below,...
Read more >CoC with method whose signature includes default values
Methods that have default parameters can be wrapped by extension classes. However, the method signature in the wrapper method must not include the...
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Default arguments - cppreference.com
have a default argument supplied in this or a previous declaration ... int); // Error: only the trailing arguments can have default values...
Read more >C#: Method overrides should not change parameter defaults
* Use the default parameter value defined in the overridden method. * Remove the default parameter value to match the signature of overridden...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also applicable to JS, not just TS
I understand the desire to make this feature ‘smart’, but I think over-engineering is delaying this from getting done. In the JSDoc spec, it suggests a few examples and all you have to do is show what is literally defined in the optional parameter as text, not interpret arguments as given by the function.
Or if it is desired to show default values based on the function itself, and not JSDoc comment, this should be split into two issues instead of merging all the JSDoc related issues into this issue.