Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Module Can';不要在我的应用程序中使用外部库_Module_Typescript - Fatal编程技术网

Module Can';不要在我的应用程序中使用外部库

Module Can';不要在我的应用程序中使用外部库,module,typescript,Module,Typescript,我创建了一个Gui库,当我在项目中测试它时,它运行良好。现在我想将其用作我的声音生成应用程序的库。 看起来很简单,但尽管我的引用或编译器选项发生了很多变化,我还是什么也得不到 我在两个tsconfig.json文件中使用1.6.2版本的typescript,目标是es5,对module使用commonjs模块解决方案是经典 我不知道这是否重要,但我使用experimentalDecorators并输出declaration文件和内联源代码映射 到目前为止,我得到的是(简化版): •图书馆文件

我创建了一个Gui库,当我在项目中测试它时,它运行良好。现在我想将其用作我的声音生成应用程序的库。
看起来很简单,但尽管我的引用或编译器选项发生了很多变化,我还是什么也得不到

我在两个
tsconfig.json
文件中使用1.6.2版本的typescript,目标是
es5
,对
module
使用
commonjs
<代码>模块解决方案是
经典

我不知道这是否重要,但我使用
experimentalDecorators
并输出
declaration
文件和内联源代码映射

到目前为止,我得到的是(简化版):


•图书馆文件

shapes.ts
shapes/rect.ts
shapes/roundrect.ts
shapes.ts是主要模块。因为我读到文件已经是模块了,所以我没有使用
module
关键字

// shapes.ts
/// <reference path="./shapes/rect.ts"/>
/// <reference path="./shapes/roundrect.ts"/>
export * from "./shapes/rect.ts";
export * from "./shapes/roundrect.ts"
--

或:

所以我尝试了很多导入语法,因为没有两个博客或文档对这种语法有相同的说法:

import  * as Shapes from '../../shapes/dst/shapes';

(或以上所有示例来自
src
而非
dst
文件夹)

所有这些示例在编辑器中都被标记为错误路径

我还尝试了以上所有示例,包括或不包括:

/// <reference path="../../shapes/rect.ts"/>

?如何使用我的库?

如果在一个文件中导出了多个类,那么使用模块是有意义的。 如果希望将类本身导出为模块,可以尝试
export=
例如:

class RoundRect {
    ....
}
export = RoundRect;

谢谢你的提示,我试试看。但是,这不适用于主库文件shapes.ts,它有许多导出。我仍然不明白为什么我每次的
require
尝试都声称路径是错误的,而
引用路径
具有相同的路径。
var MyRect = new Shapes.Rect();
import  * as Shapes from '../../shapes/dst/shapes';
import Shapes = require('../../shapes/dst/shapes');
import  {Rect, RoundRect} from '../../shapes/dst/shapes';
var Shapes = require('../../shapes/dst/shapes');
/// <reference path="../../shapes/rect.ts"/>
Cannot find module '../../shapes/dst/shapes'
class RoundRect {
    ....
}
export = RoundRect;