Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

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!

like image 684
Martin Schagerl Avatar asked Sep 27 '17 13:09

Martin Schagerl


People also ask

How do you fix Property does not exist on type?

The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.

Is missing the following properties from type?

The error "Type is missing the following properties from type" occurs when the type we assign to a variable is missing some of the properties the actual type of the variable expects. To solve the error, make sure to specify all of the required properties on the object.


1 Answers

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; } 
like image 174
Robert Penner Avatar answered Sep 20 '22 14:09

Robert Penner