Extending a class unknown at transpile time with correct typescript typings

谁说胖子不能爱 提交于 2021-02-11 12:47:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!