Tag: 打字稿

找不到模块'angular2 / angular2'

我正在用angular2和gulp开发一个节点应用程序。 我写了一个组件文件login.ts,如下所示: import {Component, View} from 'angular2/angular2'; import {FormBuilder, formDirectives } from 'angular2/forms'; @Component({ selector: 'login', injectables: [FormBuilder] }) @View({ templateUrl: '/scripts/src/components/login/login.html', directives: [formDirectives] }) export class login { } 而我的bootstrap.ts文件是: import {bootstrap} from 'angular2/angular2'; import {login} from './components/login/login'; bootstrap(login); 但是当我编译这些文件,它给了我以下错误: client\bootstrap.ts(1,25): error TS2307: Cannot find module 'angular2/angular2'. client\components\login\login.ts(1,31): error TS2307: Cannot find module 'angular2/angular2 […]

在TypeScript中导入节点并用types表示

我试图在Visual Studio代码中按照Microsoft指南设置TypeScript express / node应用程序,但将其更改为使用TypeScript,但是当涉及到使用types安装types定义时,我似乎必须安装比指南更多的包。 我正在运行以下一对命令: typings install node –ambient –save typings install express –ambient –save 但是试图用这些软件包进行构build会导致以下types的错误: error TS2307: Cannot find module 'serve-static'. 对于以下types: 哑剧 快车服务静态核心 服务静电 我可以通过安装所需的types来解决这个问题,但是它似乎应该自行完成。 我想检查一下是否缺less自动引入依赖关系的基本步骤,或者引导是否过时? 如果它是相关的,我的tsconfig.json: { "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true, "outDir": "bin", "sourceRoot": "src" }, "exclude": [ "node_modules", "typings/browser.d.ts", "typings/browser" ] } 我的tsc版本是1.8.7,我在全球安装了打字机。

如何从打字稿中使用npm模块?

我打字打字稿。 它在世界的hello世界舞台上运行良好。 我现在正在尝试使用一个npm模块: index.ts = import _ = require('lodash') console.log(_.toUpper('Hello, world !')) 这不起作用: tsc index.ts – > Cannot find module 'lodash'. (2307) Cannot find module 'lodash'. (2307) node-ts index.js – > Cannot find module 'lodash'. (2307) Cannot find module 'lodash'. (2307) 看打字稿和谷歌没有帮助。 其他S / O问题要么没有答案( 这里和这里 )或不相关。 元素: 打字稿1.8最新 是的,lodash安装npm i –save lodash并存在我的文件系统(选中) 我也做typings i […]

TypeScript或CoffeeScript

开始使用node.js来构buildWeb应用程序。 我的一位同事询问了TypeScript,它是微软的一种新语言。 我们计划使用node.js和TypeScript作为脚本引擎来启动我们的新Web应用程序。 我只是想知道是否适合使用TypeScript开发应用程序? TypeScript的未来如何?

如何运行在TypeScript中编写的Mochatesting?

安装程序:我有一个用TypeScript编写的节点项目(纯节点,没有浏览器位)。 我可以使用typescript模块中的TypeScript编译器( tsc )编译代码。 到现在为止还挺好。 不过,我想用摩卡书写testing,这就是我遇到麻烦的地方。 我试过 – –compilers ts:typescript ,但我不断收到像这样的错误: error TS5023: Unknown compiler option 'compilers'. 它看起来像mocha的命令行结束被传递给tsc ,这显然是不好的。

Typescript导入/作为vs导入/要求?

我正在使用TypeScript与Express / Node.js 对于使用模块,TypeScript手册显示以下语法: import express = require('express'); 而且typescript.d.ts文件显示: import * as express from "express"; 我也search了MSDN博客,但找不到任何东西。 哪一个在2016年初更正确? 两者之间有什么区别,如果有的话? 哪里是最好的来源,find最新的语法信息使用,所以我可以在未来find这个信息?

导入json文件时的Typescript编译器错误

所以代码很简单: calls.json {"SERVER":{ "requests":{ "one":"1" } } } file.ts import json = require('../static/calls.json'); console.log(json.SERVER); 生成的javascript是正确的,并且在运行节点js服务器时,控制台日志json.SERVER会打印“{requests:{one:'1'}}”。 打字稿编译器(commonjs)不过,不知何故并不特别喜欢这种情况,并抛出:“找不到模块”../static/calls.json'“。 当然,我试图写一个.d.ts文件,如下所示: declare module '../static/calls.json'{ var exp:any; export = exp; } 这显然会抛出:“环境模块声明不能指定相对模块名称”。 我也尝试了不同的变体,如: declare module 'calls.json' { import * as json from '/private/static/calls.json'; export = json; } 然后要求: import json = require('calls.json'); 没有正常工作,并有自己的小编译器错误:) 我想使用一个外部.json文件,因为我使用commonjs serverside和amd clientside,我想单个文件加载常量。

mongoose的打字方式…?

试图在Typescript中实现一个Mongoose模型。 谷歌search只显示了混合的方法(结合JS和TS)。 如果没有JS,我会怎么去实现User类呢? 希望能够没有行李的IUserModel。 import {IUser} from './user.ts'; import {Document, Schema, Model} from 'mongoose'; // mixing in a couple of interfaces interface IUserDocument extends IUser, Document {} // mongoose, why oh why '[String]' // TODO: investigate out why mongoose needs its own data types let userSchema: Schema = new Schema({ userName : String, password : […]

TypeScript:如何定义安装npm包的自定义types?

我喜欢在TypeScript中使用rx-node import RxNode from 'rx-node'; 我使用npm安装了rx-node $ npm install rx-node –save 我search了types定义,但没有任何结果 $ typings search rx-node No results found for search 如何为已安装的npm模块rx-node定义自定义types定义? 我应该在哪里存储types定义文件? 如何configurationTypeScript( tsconfig.json和typings.json )? 编辑:感谢Aleksey L.和大卫Bohunek我实现了定义一个rx-node.d.ts ,看起来像这样 declare module "rx-node" { import {Observable} from '@reactivex/rxjs'; import {ReadLine} from "readline"; function fromReadLineStream(stream: ReadLine): Observable<string> } 我安装了@reactivex / rxjs npm install –save @reactivex/rxjs 因为我有一个错误 node_modules\@reactivex\rxjs\dist\cjs\Observable.d.ts […]

用TypeScript导入节点模块

我试图让这个工作,但我似乎无法find任何地方的解决scheme。 当试图编译这个单一文件的应用程序: import http = require('http') http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); 使用命令“tsc app.ts –module'commonjs'”我得到以下错误(不使用–module标志给我一个额外的错误告诉我,我需要它来编译外部模块): error TS2071: Unable to resolve external module '"http"'. error TS2072: Module cannot be aliased to a non-module type.