Tag: 打字稿

打字稿错误TS1005:';' 预期

我正在编译这个打字稿文件: import http = module("http"); import express = module("express"); 有了这些参数: C:/nodejs/tsc.cmd –sourcemap cheese.ts –module commonjs C:/User/Node/ExpressProject/cheese.ts(5,21): error TS1005: ';' expected. C:/User/Node/ExpressProject/cheese.ts(6,24): error TS1005: ';' expected. 我究竟做错了什么? 即使这样,我得到相同的错误错误: module "http" {} module "express" {} import http = module("http"); import express = module("express"); 使用Typescript版本0.9.1

超时在asynchronous/等待

我与Node.js和TypeScript,我正在使用async/await 。 这是我的testing用例: async function doSomethingInSeries() { const res1 = await callApi(); const res2 = await persistInDB(res1); const res3 = await doHeavyComputation(res1); return 'simle'; } 我想为整体function设置一个超时时间。 即如果res1需要2秒, res2需要0.5秒, res3需要5秒我想有一个超时,3秒后,让我抛出一个错误。 使用正常的setTimeout调用是一个问题,因为范围已经丢失: async function doSomethingInSeries() { const timerId = setTimeout(function() { throw new Error('timeout'); }); const res1 = await callApi(); const res2 = await persistInDB(res1); const res3 […]

错误TS2304:找不到名字'Promise'

大家好,我经历了所有的解决scheme在stackoverflow上。 但是对我来说没有任何工作。 因此张贴问题。 tsconfig.json { "version":"2.13.0", "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": true, "noImplicitAny": false }, "exclude": [ "node_modules" ] } 的package.json { "name": "anguapp", "version": "1.0.0", "description": "Angular2 Gulp Typescript and Express", "main": "dist/server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "gulp […]

手动注册节点模块

题: 我在TypeScript中有一个项目,它使用了几个我在计算机上无法访问的API(它们存在于Web上)。 由于我拥有foo.d.ts文件中的所有API,因此代码将在本地编译,因此系统知道它们存在于某处。 不过,我想用NodeJS应用程序unit testing部分代码。 我可以将代码导入到节点中,但每当我到达从定义文件导入模块的代码时,都会出现以下错误: Error: Cannot find module 'messages' at Function.Module._resolveFilename (module.js:527:15) at Function.Module._load (module.js:476:23) at Module.require (module.js:568:17) at require (internal/module.js:11:18) at Object.<anonymous> (~/dev/repos/sample_typescript_fail/App.js:3:18) at Module._compile (module.js:624:30) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) … 这是有道理的,因为这个代码只是在本地定义的,并不存在。 我可以手动注册模块到NodeJS,如 Registry.register('messages', () => {…}); 这样我可以编译和testingpolyfills? 这是一个示例应用程序 package.json { "name": "sample_typescript_declare_issue", "version": […]

你如何使用打字机编写节点模块?

所以,另一个问题(如何使用打字机导入模块)的一般答案是: 1)创build一个blah.d.ts定义文件。 2)使用: /// <reference path="./defs/foo/foo.d.ts"/> import foo = require("foo"); 关键的是,你需要在你的node_modules的某个地方加载文件foo.d.ts和foo.js; 和 NAME foo必须完全匹配。 现在… 我想要回答的问题是如何编写一个可以以这种方式导入的打字稿模块? 比方说,我有一个这样的模块: – xq/ – xq/defs/Qdts – xq/index.ts – xq/base.ts – xq/thing.ts 我想从base.ts中导出模块'xq',类'Base'和thing.ts中的'Thing'。 如果这是javascript中的一个节点模块,我的index.ts将如下所示: var base = require('./base'); var thing = require('./thing'); module.exports = { Base: base.Base, Thing: thing.Thing }; 让我们尝试使用类似的打字稿文件: import base = require('./base'); export module xq { export […]

TypeScript是否为NodeJS模块访问提供了明确的公共API?

从一个节点应用程序我想要做的: var typeScript = require('typescript'); typeScript.compile('…') 我正在寻找实现编译器到生成系统,但没有访问公共API(typescript.compile等),这是不可能的。 下面是我想要做的更完整的例子,虽然下面是针对LiveScript,而不是TypeScript,在为Brunch.io构build系统编写的插件中使用: LiveScript = require 'LiveScript' sysPath = require 'path' module.exports = class LiveScriptCompiler brunchPlugin: yes type: 'javascript' extension: 'ls' constructor: (@config) -> null compile: (data, path, callback) -> try result = LiveScript.compile data, bare: yes catch err error = err finally callback error, result include: [ (sysPath.join __dirname, […]

如何在npm本地安装和运行Typescript?

我想安装和运行Typescript(即没有全局依赖)。 这是我的package.json文件: { "name": "foo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "tsc": "tsc" }, "devDependencies": { "typescript": "^1.8.10" }, "author": "", "license": "ISC" } 然后我运行: npm install npm run tsc 但是,当我运行第二个命令我得到很多错误,它不能显示所有它。 其中大部分如下所示: ../foo/node_modules/typescript/lib/lib.d.ts(5015,5): error TS2300: Duplicate identifier 'webkitTransformOrigin'. ../foo/node_modules/typescript/lib/lib.d.ts(5016,5): error TS2300: Duplicate identifier 'webkitTransformStyle'. […]

没有导出的成员/节点模块

我正在使用在这里find的5分钟快速入门启动Angular 2 / Typescript。 我遇到了一个看起来很常见的问题,但也许有点不同。 我遇到各种“无出口成员”的问题。 例子: 来自app.module.ts: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; 返回 …node_modules/@angular2/core/index" has no exported member 'NgModule'. 和 …@angular/platform-browser/index" has no exported member 'BrowserModule'. 从main.ts: import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 抛出: …@angular/platform-browser-dynamic/index" has no exported member 'platformBrowserDynamic'. 我正在运行节点版本4.4.7和npm版本3.10.5。 我明白,这些可能在本教程的上下文中通过回滚节点或npm到与本教程相关的版本来解决。 我想我想要的是解释如何使教程中的代码与当前版本的节点相关。 ETA:这些错误发生在编译,而不是执行。

带有TypeScript类的NodeJS EventEmitter

是否有可能使用types脚本类的NodeJS'events.EventEmitter? 如果是的话,怎么样? 我已经尝试了无数的变化,在最后几个小时得到这个工作,所以我不会列出他们中的任何一个。 我基本上想要做的是: export class Database{ constructor(cfg:IDatabaseConfiguration) { // events.EventEmitter.call(this); mongoose.connect(cfg.getConnectionString(), cfg.getCredentials(), function (err:any) { if (err) this.emit('error', err); else this.emit('ready'); }); } }

正确的解释NodeJS / Typescript导出/导入?

有人能请解释如何使用Typescript在NodeJS中输出和input? 我的设置是: 的NodeJS 一切都在打字稿 TSLint 分型 我正在搞出口/import,而不是做一些适当的编码,这使我疯狂,找不到任何正确的解释。 import 你可以请解释一下: var module = require ("module"); import module = require("module"); import module from "module"; import {something} from "module"; import * as module from "module"; 出口 你能解释一下吗? export = something; export default something; export interface|class something; 问题 如何在不启动的情况下正确导出/导入类 如何正确地导出/导入一个类正在启动(构build运行) 如何正确导出/导入类和接口 如何正确导出/导入类和多个接口 何时使用模块声明,什么是他们的好,为什么tslint抛出错误,如果我尝试使用它们。 我似乎无法find正确的出口与import的方式,所以我的IDE没有被红色覆盖,并向我抛出数百个错误。 一般的问题 有甚至有一种方法不能使用nodejs / typescript / […]