Tag: 打字稿

打字稿:“茉莉花”方法无法正确识别

虽然我已经添加了一个定义文件,Jasmin方法(即createSpyOjb)不被识别。 任何想法为什么会发生?

导入模块上的Node.js错误

我从TS语言规范手册(第111页)创build了这2个文件 文件geometry.ts: export interface Point { x: number; y: number }; export function point(x: number, y: number): Point { return { x: x, y: y }; } 文件game.ts: import g = require("geometry"); var p = g.point(10, 20); 我在命令行中尝试以下内容: tsc geometry.ts -d -m "commonjs" tsc game.ts -m "commonjs" node game.ts 我得到以下错误。 module.js:340 throw err; ^ Error: […]

如何导出和导入types定义?

我一直在使用TypeScript一段时间,模块系统仍然是我的一个谜。 我有这个types定义文件(appComponents.d.ts): /// <reference path="./authentication/API.d.ts"/> import express = require('express'); declare module appComponents { export interface IComponents { application: express.Application; authenticationService: MyApp.IAuthenticationService; // and so on … } } 和这个文件(index.ts): /// <reference path="./appComponents.d.ts"/> import express = require('express'); import mssql = require('mssql'); function initComponents(): appComponents.IComponents { // Components initialized here … } 两个问题: 为什么我必须使用 import express = […]

共享节点js项目和网站项目之间的代码

于是我开始编写一个打字机的国际象棋引擎作为一个副项目。 我最初希望它是一个像大多数其他国际象棋引擎,通过标准input和标准输出交互的CLI。 这样我就可以将它连接到像Arena这样的GUI,并且可以对其他引擎进行testing。 为此,我决定将其作为节点项目来完成。 我将其设置为1个UCI(通用国际象棋界面)实现和其余的棋子逻辑和AI逻辑的几个文件。 在敲打我的头几次试图理解打字稿模块,我终于得到它的工作。 现在我决定自己写一个简单的GUI作为带有html + typescript + jquery的网页会很有趣。 现在,我想使用我写的所有逻辑模块,但是我发现它是不可能的。 据我所知,你不能在浏览器中使用CommonJS,所以唯一能让它工作的方式是使用内部模块,我需要修改.ts文件来将代码封装在module X{ }然后重新编译它们每当我改变一些东西的时候,只是为了GUI。 这种情况似乎很不理想,我想知道是否有办法解决这个问题。

如何为具有构造函数的复杂外部commonjs模块(如imap)编写TypeScript声明文件?

这个问题是我早期的一个改进: 如何为具有构造函数的外部commonjs模块编写TypeScript声明文件? 我试图为imap模块编写一个声明文件: – imap on npm – node-imap这个文件应该是什么样的? 在没有find我上面提到的原始问题的满意答案之后,我意识到这个语言有一些相互竞争的特征: 任何导出或导入都会使模块成为外部模块 似乎没有办法从具有(模块级)构造函数的外部模块导出多个实体,因此共享实体必须位于模块外(环境)。 看我以前的问题(上面)。 没有办法将外部模块导入到声明模块之外的声明文件中 下面的模式是不允许的: import fs = require('fs'); declare module 'A' {} import fs = require('fs'); declare module 'A' {} 这是我到目前为止的声明文件: interface IIMAPAccount { user: string; password: string; host: string; port: number; tls?: boolean; } interface IEMail { mail: any; } interface ICriteria { […]

Typescript和NodeJS:ReferenceError:模块没有定义

我使用Typescript模板为Visual Studio( http://nodejstools.codeplex.com/ )提供了一个NodeJs控制台应用程序。 这里是基本的我的代码: app.ts: /// <reference path="Module/Module.ts" /> var foo = new Module.ModuleClass(); foo.foo(); Module / Module.ts: module Module { export class ModuleClass { foo() { console.log('Hello World'); } } } 编译器运行时没有问题,但在运行时,NodeJS找不到模块。 这是错误: var foo = new Module.ModuleClass(); ^ ReferenceError : Module is not defined 我厌倦了很多关于这个问题的事情(使用或不使用///,但我找不到任何解决scheme。 请原谅我的英语,我不是母语的人。 提前致谢 !

导出类的静态方法

是否有可能我将TypeScript的类静态方法导出到NodeJs? 例: class Help { static show() { … } } export = Help.show; 它返回它: class.Help.ts(5,19): error TS1005: ';' expected.

带有打字稿的Node.js需要和.d.ts文件

我想创build一个服务器端脚本,为此我需要“Q”,所以我包含了qdts文件。 我用这个来导入q: var Q = require("q"); 现在我收到这个错误:重复的标识符'Q' 有人知道如何解决这个名字冲突吗? 完整的启动脚本:+ ///<reference path="Scripts/typings/q/Qdts" /> ///<reference path="Server.ts" /> ///<reference path="Services/DatabaseProvider.ts" /> ///<reference path="Response/Response.ts" /> ///<reference path="Response/DataResponse.ts" /> var Q = require("q"); var di = require("ng-di"); var app = di.module("App", []); app.service("server", Server); app.service("$databaseProvider", DatabaseProvider); app.run((server: Server) => { server.run(); }); di.injector(["App"]);

编译成CommonJS不会产生NodeJS可用的文件

给定这里提供的语法(标准的ES6模块导入/导出),以及下面的文件,打字稿编译器(TSC)build立文件,将抛出Error: Cannot find module时使用NodeJS。 这是一个简单的例子: input文件 SRC / main.ts import {Example} from 'example'; let e = new Example(); SRC / example.ts export class Example {} 汇编 请注意,从Windows机器上使用npm install -g typescript版本1.5.0-beta的tsc。 tsc –rootDir src –outDir bin 输出文件 斌/ main.js var example_1 = require('example'); var e = new example_1.Example(); 斌/ example.js var Example = (function () { […]

导入一个JavaScript模块dynamic使用打字稿

我想使用CommonJS将正常的javascript模块(例如vhost )导入到我的node.js打字稿文件中。 我可以用下面这行来做: import vhost = require('vhost') 我们假设我无法在互联网上find一个.d.ts文件,但是我也不想自己写这个文件,所以我只是使用没有智能感知的vhostvariables。 编译器抱怨并抱怨: 我怎么能告诉我只是想要它是'dynamic的'(如C# dynamic关键字或'var'在正常的JavaScript),并使用上面的图片中的所有东西? 我可以创build一个vhost.d.ts文件,但我不知道该写什么: declare module 'vash' { // what to write here? }