i am trying to assign a string as an argument to give keys of my object as an argument to the method and i get this error

37 Views Asked by At

Argument of type 'string' is not assignable to parameter of type 'keyof T'. Type 'string' is not assignable to type 'never'.

interface ModelAttributes<T extends object> {
  get<K extends keyof T>(key: K): T[K];
  set(update: T): void;
  getAll(): T;
}

fetch(): void {
    const id = this.get('id'); here where i get the error 
    if (typeof id !== 'number') {
      throw new Error('cannot fetch without an id');
    }
0

There are 0 best solutions below