Martin Schagerl
Martin Schagerl

Reputation: 613

Type 'X' has no properties in common with type 'Y'

I updated typescript to version 2.5.3. Now I get many typings errors. I have following simplified situation:

export interface IClassHasMetaImplements {
    prototype?: any;
}

export class UserPermissionModel implements IClassHasMetaImplements {
    public test() {
    }
}

This code statment raise the following error: error TS2559: Type 'UserPermissionModel' has no properties in common with type 'IClassHasMetaImplements'.

Could anyone help me resolving this problem.

Thanks!

Upvotes: 37

Views: 78803

Answers (1)

Robert Penner
Robert Penner

Reputation: 6398

TypeScript's weak type detection is being triggered. Because your interface has no required properties, technically any class would satisfy the interface (prior to TypeScript 2.4).

To resolve this error without changing your interface, simply add the optional property to your class:

export interface IClassHasMetaImplements {
    prototype?: any;
}

export class UserPermissionModel implements IClassHasMetaImplements {
    public test() {}
    prototype?: any;
}

Upvotes: 44

Related Questions