Question: I am trying to determine why TypeScript allows you to overload the return type of a function to the type 'any' from a more specific type when implementing an interface. 

In my case I am working in Angular and am injecting the implemented class. 

My environment:

Visual Studio 2017

Angular Version 1.5.5

TypeScript Version 2.1.5

The following code compiles without any issue:

```
export interface IFoo {
    thing: (parameter: number) => string;
}

export class BarService implements IFoo {
    public thing = (parameter: number): any => {
        return { "whatever": parameter };
    }
}
angular.module("FooBar").service("barService", BarService);

```

So now when I attempt to consume the IFoo interface and am expecting a string to be returned from the 'thing' function call the compiler actually allows it to happen!

```
export class Whatever {
    public foo: IFoo;
    public myString: string;

    static $inject = ["barService"];
    constructor(barService: IFoo) {

        this.foo = barService;

        this.myString = this.foo.thing(0);
    }
}

```

It seems that TypeScript should fail to compile when the return type is overloaded with type 'any' because consumers of the interface are expecting a strongly typed object.

Answer: 
I'm not an expert on Typescript but based on my understanding of `any`:

<https://www.typescriptlang.org/docs/handbook/basic-types.html>

We find this comment on that page:

"We want to opt-out of type-checking and let the values pass through compile-time checks." 

So I'm guessing when the compilers sees `any`, it says "I will not confirm this type". Ergo this condition must be sufficient for the compiler to assume that the function has been implemented correctly.

I used to think of `any` as "accept anything" (which is does). But more precisely it means "Assume this is the type you want.", from what I've seen. So in this case the compiler assumes it is `string` for your convenience and allows the compile-time check to pass.
As i see it there are two places that you could expect TypeScript compiler to fail. BarService returning any and Whatever class assigning return value from thing() function to myString.

The compiler doesn't fail when you return any in your BarService because in TypeScript you can use any as a substitude for any/all Types. The type any in TypeScript is mainly thought of to make it easier to support old javascript libraries or code. Check the Any section here: <https://www.typescriptlang.org/docs/handbook/basic-types.html>. And yes can and is abused.

The compiler doesn't fail in your Whatever class because here you are using the interface that in fact does says that the thing() function returns a string. The compiler do not know about the BarService when compiling the Whatever class.