在TypeScript中不能使用导入的类作为返回类型 [英] Can't use imported class as a return type in TypeScript
本文介绍了在TypeScript中不能使用导入的类作为返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用导入的命令
类作为返回类型,即使可以创建命令
实例,如( let parser = new Command();
)
I can't use imported Command
class as a return type even if it is possible to create Command
instance like (let parser = new Command();
)
我的 tsc
版本是,
$ src git:(master) ✗ tsc --version
Version 1.8.0-dev.20151222
我错过了什么?
推荐答案
这是因为 .IExportedCommand.Command
不是一个类型但变量。您可以使用 typeof Command
或使用该类型的实际名称 commander.ICommand
。
That's because commander.IExportedCommand.Command
is not a type but a variable. You can either use typeof Command
or use the actual name of that type commander.ICommand
.
function create(args: string[]): typeof Command;
// or
function create(args: string[]): commander.ICommand;
这篇关于在TypeScript中不能使用导入的类作为返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文