Tag: 打字稿

添加服务器端代码到angular-cli项目与节点types冲突

当添加一个基本的express.jsconfiguration(使用TypeScript)到一个Angular2项目,该项目已经用angular-cli ng new [project-name]初始化了,我需要添加下面的代码来使用gulp编译express服务器: types安装 – 环境 – 保存节点 这typings/main.d.ts添加到typings/browser.d.ts和typings/main.d.ts /// <reference path="browser/ambient/node/index.d.ts" /> and /// <reference path="main/ambient/node/index.d.ts" /> 在express server.ts文件中,我可以添加一个引用而不是browser来保持TypeScript的快乐 /// <reference path="../typings/main.d.ts" /> 但是,当我离开browser.d.ts文件中的节点types引用时, ng build命令将失败: Build failed. The Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with: Error: Typescript found the following errors: C:/Users/user123/Downloads/my-catalog-master/my-catalog-master/tmp/broccoli_type_script_compiler-input_base_path-7VFCE2dg.tmp/0/src/typings.d.ts (3, 13): Subsequent variable declarations must have the same type. Variable 'module' […]

Angular 2 Module没有导出成员

在这里,我再次希望find一个快速的解决scheme: 链接< – 点击此链接查看文件夹结构 //main.ts import {bootstrap} from 'angular2/platform/browser'; import {AppComponent} from './home.main'; import {InputComponent} from './home.controller'; import {enableProdMode} from 'angular2/core'; bootstrap(InputComponent); bootstrap(AppComponent); 这是我的main.ts文件,我从家庭主要导入AppComponent,现在home.main看起来像这样: import {Component} from 'angular2/core'; @Component({ selector:'home', templateUrl:'/index/index.ejs' }) export class InputComponent { name = 'test'; } 但是,当我运行这个时,我得到: error TS2305: Module '"controllers/home/home.main"' has no exported member 'AppComponent'. ( Same goes for home.controller […]

Node / JS导入后立即创build新的实例

我想先创build一个类的实例,而不需要先导入类,然后再创buildnew类。 代替 var mainClass = require('../dist/main'); // has "class Main { … }" var mainInstance = new mainClass(); 我想要 var mainInstance = new require('../dist/main').Main(); 但是有些语法是错误的。 var main = new require('../dist/main').Main(); ^ TypeError: Class constructor Main cannot be invoked without 'new' 这甚至有可能吗? 我使用TypeScript和普通JS的组合。

在编写自定义TypeScript定义文件时,发生错误“模块名称”在…下parsing为无types模块

我找不到TypeScript定义@type/{name}为我的已安装的NodeJS包之一,所以我试图为它写一个d.ts文件,并将文件放在{project root}\typings文件夹中。 我是这样做的: // My source code: index.ts import Helper from 'node-helper-lib'; // My definition: \typings\node-helper-lib.d.ts declare….(something else) declare module 'node-helper-lib' { class Helper { … } export = Helper; } 但是,Visual Studio代码不断产生这个错误,并将红线放在declare module 'node-helper-lib' : [ts]扩充中的模块名称无效。 模块“node-helper-lib”parsing为“{project path} \ node_modules \ node-helper-lib \ index.js”中的无types模块,无法进行扩充。 这是不是合法的,因为图书馆是无types的,所以我应该被允许添加打字? 更新: 我在用: TypeScript:2.1.4 Visual Studio代码:1.9.1 节点JS:6.9.4 Windows 10 x64

如何添加自定义css和jsangular4

在angular2中,我可以将它们添加到index.html中,如下所示: <link rel="stylesheet" href="css/mycss.css"> 但是在angular 4中,它必须被添加到样式和脚本数组部分中的angular-cli.json文件中。 在我的情况下,他们似乎并没有被加载。 没有错误,但当我在浏览器中查看应用程序,我知道样式没有加载。 当我将样式和js添加到index.html文件时,它也不会被加载,我在控制台中得到一个404。 我该如何解决? 以下是我的Angular cli版本:@ angular / cli:1.0.2 Node:6.9.2

TypeScript,使用Visual Studio 2012 express进行node.js开发

如何在Visual Studio中编写,构build和运行node.js应用程序? 我在VS和node.js包上安装TypeScript扩展。 当我创buildTypeScripttypes的新项目时,只能为浏览器编写脚本。 更新 我想为node.js库自动完成和error handling

Angular2路由连接到Express路由?

当通过URL访问我的angular2应用程序的路线不工作…快递正在渲染一个错误页面。 所以我有一个path( /docs )为静态内容和其他一些静态资源提供服务,然而, /被路由到一个由angular度2pipe理的index.html。所以通过打开应用程序根目录然后点击各种路由器链接可以到一个路线eg /tutorial/chapter/1 。 但是,因为这不是我的快速应用程序中的注册路线,如果我刷新页面,我会得到一个404。 我希望能够在浏览器中inputhttp://localhost:3000/tutorial/chapter/1并获取该页面。 如何设置快递路线的所有未定义的路线angular度,并让angular处理404? 这是我的app.js : var app = express(); // html view engine setup app.set('views', path.join(__dirname, '/ng2/views')); app.engine('html', require('jade').renderFile); app.set('view engine', 'html'); app.use(express.static('ng2/views')); app.use(express.static('ng2/public')); app.use('/node_modules', express.static(__dirname + '/node_modules')); // uncomment after placing your favicon in /public app.use(favicon(path.join(__dirname, 'ng2/public', 'favicon.png'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); //all static […]

由打字稿生成的定义文件(.d.ts)不能与package.jsontypes一起使用

我使用tsc编译器的–declaration参数从我的打字稿项目创build了一个定义文件(d.ts)。 但是这个生成的定义文件显然不起作用,当我尝试发布与在npm package.json属性typings 包 。 我创build了另一个项目来testing它。 它抱怨的信息是:“ 导出的外部包文件types文件'… d.ts'不是一个模块,请联系包作者更新包的定义 ”。 这是我的源文件: MyInterface.ts export interface MyInterface { MyProperty: string; } MyClass.ts import {MyInterface} from './MyInterface'; export class MyClass implements MyInterface { get MyProperty(): string { return "MyString"; } } MyInheritedClass.ts import {MyClass} from './MyClass'; export class MyInheritedClass extends MyClass { public MyMethod(): number { return 1; […]

Typescript + webpack(带有热重载)+ NodeJS

面对问题 – build立基于TypeScript的项目原型。 它包含客户端脚本和服务器部分(带有ExpressJ的NodeJs)。 我想有一个打包机的webpack,并使用热重新加载function,以查看飞行中的变化。 最初,我使用了react-transform-b​​oilerplate-ts ,但那里的问题 – 开发服务器的入口点是js文件。 我想这应该是ts,因为我想包括我的快速configuration等。 那么,有没有人有好的样板(遵循项目结构的最佳实践)来创build包含以下内容的项目: 客户端(React)和服务器(打字稿) 后端使用NodeJs和ExpressJs(打字稿) 客户端和服务器支持热重新加载(因为我明白最好的select – 是重新加载的webpack选项,而不是吞咽任务,运行观看)。 或者,也许你可以给我很好的build议,如何以适当的方式configuration这种东西。 非常感谢

从几个TypeScript类创build一个CommonJS模块

我试图找出将我的应用程序分割成几个可供其他应用程序使用的CommonJS模块的最佳方法。 我有5个TS类,我想把它们作为一个CommonJS模块捆绑在一起。 然后我打算把这个模块发布到一个私有的NPM库,这样它可以被其他应用程序使用。 理想情况下,我想打包相关的* .d.ts定义文件。 什么是最好的方法来做到这一点? 我正在使用外部TS模块,但是这些模块为每个TS类生成一个单独的CommonJS模块。