Consider the following TypeScript code sample.
var checkEqual = function (a:any, b:any) {
if(a == null)
{
return false;
}
}
When I will compile it, it will generate the corresponding JavaScript file without any compile time error as below:
var checkEqual = function (a, b) {
if (a == null) {
return false;
}
};
But when I run JSHint on the compiled JavaScript code/file I will have following error/warning:
Use === to compare with null
I want the compiled JavaScript code from TypeScript to be JSHint compatible (no errors and warnings should be there). That means either it should generate the correct code or it should give compile time error.
PS: I did not know about tslint before, but even after using it, it is not compiling JavaScript compatible with JSHint (JSHint is still throwing warnings).
It's simply not possible! TypeScript was never built with the goal to create code that is compliant with a linter. When using TypeScript you have to think of the generated JavaScript as bytecode. There is no reason to look at your bytecode.
Some linters may even bother you with problematic use of this
. Which in fact should be used very carefully in ES5. But when using TypeScript/ES2015 class definitions you need to use this
a lot and transpiling to ES5 will create a lot of them. So creating code that matches your linter will force you to not use a lot of features of TypeScript.
So if you want to lint bytecode, then you should write bytecode ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With