Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to enforce method return types on Typescript classes via a tslint rule?

I've read the tslint rules here and while it looks like the typedef rule's call-signature option is what I want, it doesn't complain about the lack of a return type.

Anyone know the rule (f one exists) to enforce return types on class methods?

like image 531
icfantv Avatar asked Mar 14 '17 18:03

icfantv


People also ask

What does TSLint do?

TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.

What is TSLint rules?

no-empty-interface - Forbids empty interfaces. no-for-in - Ban the usage of for…in statements. no-import-side-effect - Avoid import statements with side-effect. TS Only Has Fixer. no-inferrable-types - Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.

How do I disable TSLint?

You can suppress TSLint rules for the current file and even for the current line. WebStorm automatically generates disable comments in the format /* tslint:disable:<rule name> or // tslint:disable-next-line:<rule name> and places them on top of the file or above the current line respectively.


1 Answers

Turns out this can be done via:

"typedef": [   true,   "call-signature",   "property-declaration" ] 

More info: https://palantir.github.io/tslint/rules/typedef/

like image 95
icfantv Avatar answered Oct 08 '22 11:10

icfantv