问题
I want to extend a class which does not exist at transpile time. It is only loaded runtime (global library). However, we got the type definitions ofthe library. Is there any other way than using any
for the base class which doesn't have the advantages of typing?
Example with following error message: Type 'A' is not a constructor function type.
/* Some external library with typings. */
class A {
constructor() {
}
}
/* Factory to inject dependency which does not exist at transpile time, only at runtime.
However, we know the injected class is of type A because we have its typings.
*/
function BFactory(injectedA: A) {
class B extends injectedA {
}
}
来源:https://stackoverflow.com/questions/66028715/extending-a-class-unknown-at-transpile-time-with-correct-typescript-typings