tslint-consistent-codestyle
tslint-consistent-codestyle copied to clipboard
no-unused: false positive with substitution type inside mapped type
trafficstars
type Values<T> = T extends {[K in keyof T]: infer U} ? U : never;
U is marked as unused but is actually referenced in the then branch of the conditional type
It's similar but not exactly the same:
type Foo<T> = T extends { new (a: infer A): any } ? A : never;
A is marked as unused.
We can make and indirection, though:
interface Baz<A> { new (a: A): any }
type Bar<T> = T extends Baz<infer A> ? A : never;
I think in general it affects many inferred types.
/**
* Pick the Nth Param for any function with the first parameter marked by the 0 index.
*/
export type NthParam<GFunction extends AnyFunction, GIndex extends number> = GFunction extends (
...args: infer GArgs // => Flagged as unused
) => any
? GArgs[GIndex]
: never;
The linter warns me that GArgs is unused.