Revisiting _ underscore for unused parameters: create `unused` type
See original GitHub issueSearch Terms
_, underscore, noUnusedParameters, --noUnusedParameters, tslint, ts-lint, #9458, palantir/tslint#3442
Suggestion
Create an unused
type for function parameters that are not used.
Use Cases
Can be used to clearly state unused parameters, while still playing nice with --noUnusedParameters
and linters enforcing variable name conventions.
May also help in cases such as
- #14154 - destructuring will fail at runtime if argument is not an object
- #18420 -
type Foo<usused> = { }
?
Examples
1. Unused parameter
function typicalNodeCallback(err: unused, data: any) {
// do stuff with `data`
}
2. Using unused parameter is an error
function expressMiddleware(req: unused, res: any) {
const body = req.body // ERROR!
}
Checklist
My suggestion meets these guidelines:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:39
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Michael Jackson on Twitter: "TypeScript experts: is there a ...
Revisiting _ underscore for unused parameters: create `unused` type ... Create an unused type for function parameters that are not used.
Read more >typescript - Skip type check on unused parameters
Using the underscore trick is still very useful in Typescript. Like I mentioned in my original answer say if you was using express...
Read more >Underscores for unused parameters? : r/learnjavascript - Reddit
In Visual Studio Code (JavaScript code or TypeScript code), an unused parameter is displayed in a different color – unless its name starts...
Read more >Ignore fist parameter of function if unused with a simple
If you ever find yourself in a situation where you need to implement function receiving multiple parameters, but you don't really need all ......
Read more >About the unused-argument syntax in R2009b
For another example, suppose you write a function that has to take three input arguments (because another function is always going to pass ......
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
I don’t think adding a type solves anything. It actually loses type information: Sometimes you need to declare the type of a parameter even if you don’t use is. For example in methods of a base class that are meant to be overridden.
At the very least, a function parameter should not be considered to be “unused” if a parameter that comes after it is used. In that case, the “unused” parameter is actually serving a purpose by taking up a slot in the argument list.