Generate a warning/error when TypeScript infers 'any' as return type?

Viewed 34

Is there a way I can configure TypeScript to generate a warning/error when it infers any as the return type of a function? If it infers number or something it's not so bad, but any opts out of type checking and has tripped me up several times, yet I have to remember to check every function to make sure it's not returning any. I'd like this to be flagged up to me.

As an example of code that would cause this to be flagged up, ideally:

export default class MyClass {
    // ...

    #myMethod = (e: any) => {
        return e && e.target && e.target.hasName("stage");
    };

    // ...
}
0 Answers
Related