Currently, I am utilizing the AngularJS framework (version 1.5.8) in tandem with the latest TypeScript files (2.8.0). However, upon updating to the newest version of TypeScript, the code below is failing to compile.
The IMappingService interface:
export interface IMappingService {
/**
* This interface deals with validating the mapping of a T object from one type to another and returning the new mapped object
* @param obj The object to validate
* @param type The type of the object
* @returns {T} The newly validated and mapped object
*/
validate<T>(obj: any, type: string, fields: string): T;
}
The implementation of the interface:
export default class MappingService implements IMappingService {
public validate<T>(obj: any, type: string, fields: string): T | T[] {
let parsedFields = null;
const replacedFields = fields.replace(/'/g, '"');
parsedFields = JSON.parse(replacedFields);
let tempobject = obj;
if (obj instanceof Array) {
tempobject = obj[0];
if (!tempobject) {
return [];
}
}
....
return obj;
}
An error message that I am encountering states:
Property 'validate' in type 'MappingService' is not assignable to the same property in base type 'IMappingService'.
Type '<T>(obj: any, type: string, fields: string) => T | T[]' is not assignable to type '<T>(obj: any, type: string, fields: string) => T'