Tslint: FR: Support no-undef rule: Check undeclared variables

Created on 12 Nov 2017  ·  6Comments  ·  Source: palantir/tslint

This one of the very useful of eslint, could tslint support it?
https://eslint.org/docs/rules/no-undef

Most helpful comment

@ajafff
The reason why one may want to use it, is because one can accidentally access window property.

Here is an example,

// a.ts
export const postMessage  = (message: string) => console.log(message);
// Forget to import, but use libs: dom... so it compliles perfectly
// import { postMessage } from './a';

postMessage('hello'); // Oooops

All 6 comments

Why would you need a lint rule for that? The compiler already shows an error if it can't find a declaration of an identifier.

Why would you need a lint rule for that?

@ajafff Because it provides a great real time developer experience showing me all undeclared variables with a red underline on editor, specially useful after moving some code around.

But nevermind, I think it was a bug with my vscode, because now it's showing red underline on undeclared vars just fine.

@ajafff
The reason why one may want to use it, is because one can accidentally access window property.

Here is an example,

// a.ts
export const postMessage  = (message: string) => console.log(message);
// Forget to import, but use libs: dom... so it compliles perfectly
// import { postMessage } from './a';

postMessage('hello'); // Oooops

Because it provides a great real time developer experience showing me all undeclared variables with a red underline on editor, specially useful after moving some code around.
But nevermind, I think it was a bug with my vscode, because now it's showing red underline on undeclared vars just fine.

Actually, this stopped happening in my VSCode since I disabled eslint. Did anything change?

Any update on this feature request?

Hi! TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. ☠️
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. ✅

As for this particular feature request, TypeScript will still inform you if variables are unused or undefined - particularly if you enable --strictNullChecks. Check with your editor if that's not being surfaced for you.

Was this page helpful?
0 / 5 - 0 ratings