关于TypeScript的用法

关于TypeScript。见下面的代码。

interface MyInterface { }

class MyClassA implements MyInterface { }

class MyClassB implements MyInterface { }

const createMyInterface = (_interface: any) => {
  return new _interface();
}

createMyInterface(MyClassA);
createMyInterface(MyClassB);

我想实现的是,在调用 createMyInterface() 方法的时候,可以明确提示出,需要传递的是一个 implementsMyInterface接口 的 的定义。

请问在 _interface: any 这里的 any 可以换成什么写法?

阅读 1.6k
1 个回答
interface MyInterface { }
class MyClassA implements MyInterface { }
class MyClassB implements MyInterface { }
const createMyInterface = (_interface: MyInterface) => {
  return new _interface();
}

createMyInterface(MyClassA);
createMyInterface(MyClassB);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进