Skip to content

linter: no-unnecessary-type-arguments false-positive for a specific generic usage #21464

@Simek

Description

@Simek

What version of Oxlint are you using?

1.60.0 (0.21.0 oxlint-tsgolint)

What command did you run?

oxlint --type-aware --fix

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "rules": {
    "typescript/no-unnecessary-type-arguments": "error",
  }
}

What happened?

After latest oxlint and oxlint-tsgolint update there were few new unnecessary type arguments detected, however it looks like there is one false-positive warning relate to generic usage, i.e.:

export function throttlePromiseWithResult<R, T extends (...args: any) => Promise<R>>(wrapped: T) {
  return function (this: any, ...args: Parameters<T>): Promise<R> {
    return new Promise<R>((_, reject) => ({
      run: () => wrapped.apply(args),
      reject: () => reject(new Error('Throttled')),
    }));
  };
}

export function throttlePromise<T extends (...args: any) => Promise<void>>(
  wrapped: T,
): (...args: Parameters<T>) => Promise<void> {
  // typescript-eslint(no-unnecessary-type-arguments): This value can be trivially inferred for this type parameter, so it can be omitted (related to `T` in `throttlePromiseWithResult` call)
  const throttler = throttlePromiseWithResult<void, T>(wrapped);
  return async function (this: any, ...args: Parameters<T>): Promise<void> {
    return throttler.apply(this, args).catch(() => {});
  };
}

However, removing T (which happens on auto-fix) leads to TypeScript error:

TS2558: Expected 2 type arguments, but got 1

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions