Skip to content

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

@drwpow

Description

@drwpow

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!

Metadata

Metadata

Assignees

Labels

A-linterArea - Lintergood first issueExperience Level - Good for newcomers

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions