Suppose we have the following. How do we override the value in a subclass, but keep it readonly, without silencing errors on the constructor?
class FooBar {
static readonly elName = 'foo-bar'
}
class SubClass extends FooBar { // Error 2417: Class static side 'typeof BottomNavigation' incorrectly extends base class static side 'typeof NavigationShell'.
static readonly elName = 'sub-class'
}
If the TypeScript placed the error on elName instead, then I could ignore the error there, which would make sense. But having to silence the error on the class name would potentially silence other errors:
Is there another way to do it? Each subclass should have a readonly unique name, such that it can be used witha know string type, such as
type Foo = {
[SubClass.elName]: number
}
const obj: Foo = {
[SubClass.elName] = 123 // ok
}
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.