I am using D3 and all callback functions should receiving 3 parameters.
"ValueFn
I defined my event listeners as
on("mouseover", (d: any, index: number, elems: SVGGElement[]): void => {
d3.select(elems[index]);
})
When I compiling to JS file and running via LINT/JSHINT no errors, however by enabling in tsconfig.json
"noUnusedParameters": true
I am getting errors: "error TS6133: 'd' is declared but its value is never read."
"d" is first argument you cannot avoid it. So, why TS compiler so crazy and cannot recognize it?
Prefix the unused parameter with an underscore, as in _d.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#flag-unused-declarations-with---nounusedparameters-and---nounusedlocals
Why do we need that? It's kind of strange all my express functions will contains different parameters:
route.get("/foo1", (_req: Request, _res: Response, next: NextFunction) => {
next();
}
route.get("/foo2", (_req: Request, res: Response, next: NextFunction) => {
res.send("HELLO WORLD!");
next();
}
route.get("/foo3", (req: Request, res: Response, next: NextFunction) => {
res.send(req.params.helloworld);
next();
}
@dgofman-equinix You enable a feature that will error on unused parameters, then complain that it errors about unused parameters? If you don't like this feature, then don't enable it. The _-prefix is a way to opt-out of this feature by being explicitly saying "I'm aware this is not used, ignore it".
It's --noUnusedParameters, not --noUnusedNonleadingParameters. Lots of options available to you and it's not a bug that we literally do the thing the flag is called.
Prior discussion at #9458
Most helpful comment
Why do we need that? It's kind of strange all my express functions will contains different parameters: