class Obj {
constructor() {}
a() {}
b() {}
c() {}
plugins: Record<string, Function> = {
d() {},
e() {},
};
useFunc(name: string) {
return this[name] || this.plugins[name];
}
}
const theObj = new Obj();
结果报错:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Obj'.
No index signature with a parameter of type 'string' was found on type 'Obj'.
试试