typescripttypescript1.8

Why can I not extend 'any' in Typescript?


I want to make a placeholder interface for classes that use an external library. So I made:

export interface IDatabaseModel extends any
{
}

I'd rather do this and add methods later (e.g. findAll()) than mark all my classes as 'any' and have to manually search and replace 'any' in hundreds of specific places with 'IDatabaseModel' later.

But the compiler complains it cannot find 'any'.

What am I doing wrong?


Solution

  • The any type is a way to opt-out of type checking and so it doesn't make sense to use it in an environment where type checking is done.

    You could instead add your methods to the interface as you use them:

    export interface IDatabaseModel
    {
        findAll(): any;
    }
    

    Edit: See Paleo's answer for using a type alias in the meantime.