【问题标题】:Can't use imported class as a return type in TypeScript不能在 TypeScript 中使用导入的类作为返回类型
【发布时间】:2016-03-31 21:45:35
【问题描述】:
我不能使用导入的 Command 类作为返回类型,即使可以创建 Command 实例,例如 (let parser = new Command();)
我的tsc 版本是,
$ src git:(master) ✗ tsc --version
Version 1.8.0-dev.20151222
我错过了什么吗?
【问题讨论】:
标签:
import
module
typescript
export
ecmascript-6
【解决方案1】:
那是因为commander.IExportedCommand.Command is not 是一个类型但一个变量。您可以使用typeof Command 或使用该类型的实际名称commander.ICommand。
function create(args: string[]): typeof Command;
// or
function create(args: string[]): commander.ICommand;