oxc
oxc copied to clipboard
eslint(no-undef) doesn’t understand TypeScript generics
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!
This rule is still under in development, there is more discussion in #732 if you would like to know:)
The TypeScript generics problem is related to https://github.com/oxc-project/oxc/issues/2023
https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_undef.rs is currently under nursery.