Answer the question
In order to leave comments, you need to log in
How to call a class function through lists in typescript?
in js you can easily do it like this
let test = new Myclass();
let list =['get','set'];
test[list[0]](arg)
Answer the question
In order to leave comments, you need to log in
The reason is described in the error text. You need to use a tuple.
class Flintstone {
say() {
console.log(` Yabba-Dabba Do`);
}
}
let fred = new Flintstone();
let list =['say'] as const;
fred[list[0]];
enum
orconst enum
class Flintstone {
say() {
console.log(` Yabba-Dabba Do`);
}
go() {
}
}
let fred = new Flintstone();
const enum FlintstoneMethod {
Say = `say`
}
let keys: FlintstoneMethod[] = [FlintstoneMethod.Say];
fred[keys[0]]();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question