Tag: typescript

使用TypeScriptinheritance不起作用浏览器端

先前对此的讨论: inheritanceTypeScript和导出的类和模块 这是从ValidatorMessage.class.ts生成的源代码: ///<reference path='./def/lib.d.ts'/> ///<reference path='./def/node.d.ts'/> var __extends = this.__extends || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; var message = require("./Message.class"); var ValidatorMessage = (function (_super) { __extends(ValidatorMessage, _super); function ValidatorMessage() […]

tsconfig compilerOptions“module”:“system”not working

在angular2 5分钟的教程中,他们使用“system”作为tsconfig中的模块。 我有systemjs作为node_module,但是当试图启动我的服务器时,我得到的System is not defined ,从编译js文件,看起来像这样的第一行: System.register(['http', 'express', './config/index', 'path'], function(exports_1) { 为什么System未定义,即使我把它作为一个节点的依赖? 我试图改变它commonjs,然后编译的js看起来更简单。 但是,然后我在angular度应用程序中得到错误。 我为了与SystemJs一起工作而错过了什么? 编辑 我想我解释我的问题是不好的。 从导入模块更改为我的server.ts文件“JavaScript风格”( var http = require('http'); )我猜“打字稿样式”( import * as http from 'http'; ) import * as http from 'http';我开始得到错误上面指定。 当做它的JavaScript风格编译js看起来就像ts( var http = require('http'); )然而,当它做“打字稿风格”它被编译与模块导入使用系统(指定的代码行以上)。 所以当我试图启动节点服务器而不是在浏览器中出现这个错误。 我尝试更改编译选项“模块”为“commonjs”而不是“系统”在tsconfig.json,这样做会导致浏览器错误 ( 这个错误 ,只有解决scheme似乎不适合)一些奇怪的原因,所以我想我会尝试与“系统”。 但后来我遇到了没有定义System的问题。 那么在启动节点服务器时如何访问系统呢?

无法安装@types软件包:主机密钥validation失败

当我尝试运行以下命令时: npm install @types/react 我得到以下输出: npm ERR! git clone git@github.com:types/react Cloning into bare repository 'C:\Users\lifeg\AppDa ta\Roaming\npm-cache\_git-remotes\git-github-com-types-react-e0f5ee6a'… npm ERR! git clone git@github.com:types/react Host key verification failed. npm ERR! git clone git@github.com:types/react fatal: Could not read from remote repository. npm ERR! git clone git@github.com:types/react npm ERR! git clone git@github.com:types/react Please make sure you have the correct access […]

无法编译简单的TypeScript node-ts示例

我正在学习https://github.com/TypeStrong/ts-node 。 我写了两个文件作为一个简单的例子。 它们都在同一个目录中,它目前不在package.json中 /package.json /src/build-lib/run-ts.js /src/build-lib/Test.ts 运行ts.js require('ts-node').register(); const Test = require('./Test.ts').Test; // Tried with and without .ts extension const tester = new Test(); tester.log('Message'); Test.ts export class Test { log(message: string) { console.log(`Test ${message}`); } } 我正在运行以下脚本: ts-node src/build-scripts/gen-xml.js 而且我收到以下编译错误 /Users/jmendes/gitclient/vcd-ui/content/core/node_modules/ts-node/src/index.ts:319 throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)) ^ TSError: ⨯ Unable to compile […]

Mongoose:“TypeError:”监听器“参数必须是一个函数”连接

我试图用typecript 2.2.1,expression4.15.2和节点v7.7.2使用Mongoose ,但是当我尝试连接到MongoDB它会引发此错误: TypeError: "listener" argument must be a function at Socket.once (events.js:307:11) at Socket.connect (net.js:943:10) at Socket.connect (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:76:27) at Object.exports.connect.exports.createConnection (net.js:76:35) at Connection.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/connection.js:399:11) at Pool.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/pool.js:638:16) at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/topologies/server.js:384:17) at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/server.js:361:17) at open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:226:19) at Db.open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:249:44) at NativeConnection.doOpen (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:58:11) at NativeConnection.Connection._open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:531:15) at /home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:289:11 at new wrappedPromise (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:372:16) at NativeConnection.Connection.open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:288:17) […]

无法在Gulp下运行项目

我是前端开发新手,我有一些现有的项目,我无法运行。 文档说,要运行我应该执行的项目: $ gulp && gulp serve 但是,我收到以下错误: /home/alex/some/project/node_modules/@types/gulp/index.d.ts(15,15): error TS2430: Interface 'Gulp' incorrectly extends interface 'Orchestrator'. Types of property 'task' are incompatible. Type 'AddMethod' is not assignable to type '{ (name: string): Task; (name: string, fn: TaskFunc): void; (name: string, dep: string[], fn: Tas…'. Type 'Orchestrator' is not assignable to type 'Task'. Property 'fn' […]

Inversify:与类名称的上下文注入

我正在尝试使用inversify将注入器注入到不同的类中。 我想将目标类名称传递给logging器对其进行分类。 问题是我无法从创build绑定的位置访问目标名称: container.bind<log4js.Logger>(Types.Logger).toDynamicValue(context => { let className = context….?; // Finds class name return log4js.getLogger(className); }); 除了在接收logging器的对象中创buildlogging器之后设置logging器之外,还有其他方法吗? 谢谢! 安托万

从打字稿模块自动生成index.d.ts,types定义

如果我有一个TypeScript模块保存为my-function.ts,如下所示: export function myFunction (param: number): number { return param } 这将以任何方式编译为JavaScript,并将其types定义放宽。 然后我可以创build一个index.d.ts文件来声明这个模块的定义,但是重新定义/重新定义这个定义似乎有点繁琐。 有没有办法从my-function.ts文件自动生成types定义到一个index.d.ts文件?

使用Node.js访问Azure表存储

我一直在使用node.js在Visual Studio中编写一个打字稿应用程序来存储和访问Azure表格存储中的数据。 我一直遇到一些麻烦,我find的教程。 我还没有得到一个正常工作。 我在我的机器上安装了节点,并在azure色的地方安装了一个桌面存储。 我不确定在Visual Studio中需要做什么来获得所有必要的包/模块/任何正确安装的东西。 我读过的许多教程都使用了express.js,或者有“npm install”编辑的东西,虽然我没有任何问题运行这些命令,但我并不真正了解我要安装的是什么。 tl; dr我想创build一个html页面,我可以使用node.js,typescript和visual studio将项目提交到azure表格存储和从Azure表格存储显示 另外:如果需要的话,我愿意放弃打字稿,转而使用javascript。

Typescript在terminal中使用tsc编译types脚本时出现错误

gowd95@gowd:~/Desktop/myapp/src/app$ tsc greeter.ts ../../node_modules/@types/core-js/index.d.ts(39,27): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(47,36): error TS2304: Cannot find name 'Iterable'. ../../node_modules/@types/core-js/index.d.ts(226,38): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(231,35): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(236,37): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(349,33): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(350,31): error TS2304: Cannot find name 'IterableIterator'. ../../node_modules/@types/core-js/index.d.ts(351,34): error TS2304: […]