I am searching for a method to assign a name string within a class and utilize it in the abstract class at the constructor level, without the need for a function. Opening up the constructor is not an option due to using typedi
.
You can access the playground link here.
Uncaught TypeError: this.name is not a function
abstract class Root {
abstract name(): string
notFoundError = new Error(`${this.name()} not found`)
}
class Use extends Root {
name = () => 'User'
}
const x = new Use()
throw x.notFoundError
This approach is not what I'm seeking:
abstract class Root {
abstract name: string
notFoundError = () => new Error(`${this.name} not found`)
}
class Use extends Root {
name = 'User'
}
const x = new Use()
throw x.notFoundError()
I am specifically interested in notFoundError
not being treated as a function.