Unique interface
export interface DataService {
getByTypeId<T extends number | string>(id: T): Promise<SomeType>;
}
Additionally, the implementation
export class BService implements DataService {
async getByTypeId(id: number): Promise<SomeType> {
// custom logic
}
//Other methods will be added here
}
Furthermore, the error message encountered:
Property 'getByTypeId' in class 'BService' does not match the property in the base
type 'DataService'.
Type '(id: number) => Promise<SomeType>' is not compatible with type '<T extends
string | number>(id: T) => Promise<SomeType>'.
Parameters 'id' and 'id' have incompatible types.
Type 'T' cannot be assigned to type 'number'.
Type 'string | number' cannot be assigned to type 'number'.
Type 'string' cannot be assigned to type 'number'.ts(2416)
A few attempts that have been made:
getByTypeId<T extends number>(id: T): Promise<SomeType>; //Works, but may need methods with id type of string
And,
getByTypeId<T>(id: T): Promise<SomeType>; //still results in errors
References followed include Official Documentation. Any ideas, thoughts, or additional resources would be greatly appreciated!
Grateful for any insights or suggestions!