oxc icon indicating copy to clipboard operation
oxc copied to clipboard

eslint(no-undef) doesn’t understand TypeScript generics

Open drwpow opened this issue 1 year ago • 2 comments

Given the following TypeScript code, it throws an error:

⚠ eslint(no-undef): Disallow the use of undeclared variables
function resolve<T>(path: string): T {
  return { path } as T;            ─
}

help: 'T' is not defined.

I understand this may just be a conflict between enabled rules; if so, maybe just adding a note in doc about recommended TS settings?


Also as a similar-but-slightly-different error, what’s the recommended way to handle builtin libraries?

⚠ eslint(no-undef): Disallow the use of undeclared variables

const root = new URL("../", import.meta.url);
                 ───
help: 'URL' is not defined.

I understand throwing an error for “magically-loaded” globals like test runner expect() calls. But for built-in DOM libraries, is there a recommended setup to allow this?


For both, I realize it may just require documentation, but wanted to ask for my own understanding. Thanks for such an amazing project!

drwpow avatar Jan 19 '24 19:01 drwpow

This rule is still under in development, there is more discussion in #732 if you would like to know:)

mysteryven avatar Jan 21 '24 10:01 mysteryven

The TypeScript generics problem is related to https://github.com/oxc-project/oxc/issues/2023

Dunqing avatar Jan 22 '24 02:01 Dunqing

https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_undef.rs is currently under nursery.

Boshen avatar Aug 18 '24 06:08 Boshen