tslint-consistent-codestyle icon indicating copy to clipboard operation
tslint-consistent-codestyle copied to clipboard

no-unused: false positive with substitution type inside mapped type

Open ajafff opened this issue 7 years ago • 2 comments
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

ajafff avatar Jul 19 '18 20:07 ajafff

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;

InExtremaRes avatar Dec 22 '18 23:12 InExtremaRes

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.

ifiokjr avatar Feb 05 '19 14:02 ifiokjr