#How to convert a string array to an function interface?

2 messages · Page 1 of 1 (latest)

cedar blade
#

Hey, lets say i have a class test
How can Type my class that the array of strings it recives is the interface for some of the methods on it.

for example

class test {
  constructor(tests:string[]) {
    this.hello = (test) => {console.log("your test is" + test)}
  }
  hello
}
// and now when i create it like this
const a = new test(["example1","example2"])
a.hello("") // <== now typescript should display that i can only put as the callable argument example1 or example2 


cedar blade
#

!solved