How to lint anonymous functions parameters with type reference as invalid?

78 views Asked by At

I would like to inspect for anonymous (array) function parameters that have type reference, because the type reference used there is usually wrong. An example of what I often see in the RxJS code:

interface Point {
  x: string;
  y: string;
}

// Angular - route: ActivatedRoute
this.route.queryParams
  .pipe(
    map((params: Params) => ({
      x: params.x,
      z: params.z
    }))
  )
  .subscribe((point: Point) => {
    const x = point.x;
    const y = point.y;
  });

None of the arrow functions parameters in map and subscribe should include type reference because it acts like cast and the type error above (property y vs z) is not reported by typescript.

Is there any inspection in IntelliJ IDEA or ESLint which can detect this? Or any other way how to prevent this in the code and let typescript infer the correct parameter type?

0

There are 0 answers