Reputation: 663
Is there an option to tell the TypeScript compiler to obey certain "rules" such as naming anonymous functions, always add the "use strict" declaration, and to always use braces?
For example, whenever you use the "extends" keyword for class inheritance, for instance, TypeScript will output this function:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
My team's JSHint rules require "curly" braces around conditionals, and require named anonymous functions (technically "named functional expressions"). Basically I'd like TypeScript's transpiler to produce better quality JavaScript code, in terms of style as opposed to efficiency (although well-performing code is also important, of course).
We can use tslint to lint our TypeScript, but I'd like to also ensure that the generated code also meets certain quality standards.
Upvotes: 0
Views: 343
Reputation: 11710
The style standards are there to help programmers read code and avoid mistakes. You'll never be reading or otherwise interacting with compiled code, because you should have source maps. If you're never going to see it (writing, debug, or stack traces), then why does it need to look good? It doesn't, so this isn't implemented.
What you can and should do, though, is set up JSHint to ignore js files produced by TypeScript.
Upvotes: 4