In typescript, for in loop is used to report errors.

I defined a file api.ts:

export default {
    login: "/account/login post"
}

introduce import api from". / api"

into another file

then loop through the api

for(const key in api) {
     console.log(api[key]);
}

the error message: Element implicitly has an "any" type because type" {login: string;} "has no index signature. is reported at this time.

ts version: 3.0.0

which god has encountered this kind of problem, please let me know, thank you!

Dec.19,2021

resolved. Post my solution:

import api from './api'



const Api: any = api;   //


for(const key in Api) {
    APIFunction[key] = gen(Api[key])
}

just started to learn ts, to write here is not, read the document, I solved this.

     interface Person {
      name: string;
      age: number;
     };
     let i:any;
     let person: Person = {
        name: 'dc',
        age: 35
      };
      const c = <T, K extends keyof T>(o: T, name: K): T[K] => {
        return o[name];
      };
      for(i in person){
        c(person,i)
      }
      
      
Menu