Element implicitly has an ‘any’

  1. function proxify(obj: any) {
  2. // 解决办法:可一个给 res 赋值为 any 类型
  3. //let res = {};
  4. let res:any = {};
  5. for (let k in obj) {
  6. // Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
  7. No index signature with a parameter of type 'string' was found on type '{}'.
  8. res[k] = {
  9. set() { },
  10. get() { }
  11. }
  12. }
  13. return res;
  14. }

Type ‘Proxy’ is not generic.

  1. // 报错原因是 Proxy 没有设置泛型
  2. type Proxy = {
  3. name: string,
  4. age: number
  5. };
  6. type Proxify<T> = {
  7. // Proxy<T[P]> 报错 Type 'Proxy' is not generic.
  8. [P in keyof T]: Proxy<T[P]>
  9. };

解决办法

  1. type Proxy<T> = {
  2. name: string,
  3. age: number
  4. };