Tag: 打字稿

使用Visual Studio代码将TypeScript编译为JavaScript

我是NodeJS和TypeScript的新手,我想从设置我的项目文件夹开始。 我已经有我的tsconfig.json { "compilerOptions": { "outDir": "./build", "module": "commonjs", "target": "es5", "noImplicitAny" : false }, "files": [ "./src/**/*.ts" ], "exclude": [ "node_modules" ]} 和package.json { "name": "crm", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } 这是我简单的目录结构: crm/ |-src/ |- main/ […]

当npm启动我的Angular2项目时,重复的标识符导出错误

当我通过npm start命令运行我的Angular2项目时,我得到了重复的标识符导出错误,我search了很多,但找不到确切的解决scheme,我可以在下面findpackage.json,typings.json和tsconfig.json。 问候阿尔珀 package.json { "name": "Angular2SampleProject2", "version": "1.0.0", "scripts": { "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" –kill-others –success first", "lint": "tslint ./app/**/*.ts -t verbose", "lite": "lite-server", "pree2e": "webdriver-manager update", "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"", "test-once": "tsc && karma start karma.conf.js […]

为什么TypeScript找不到名字“Express”?

我正在使用TypeScript开始一个快速应用程序。 以下是app.ts中的代码: import express = require("express"); let app: Express = express(); 我已经安装了Express使用 npm install –save express 我已经安装@ types / express使用: npm install –save @types/express 我正在使用Visual Studio代码(1.10.2)。 当我将鼠标hover在express()函数上时,intellisense会build议它返回一个“Express”types的对象。 所以,我已经声明了这个types的“app”variables,但是VS Code在它下面放了一个红色的波形,并且抱怨它找不到“Express”的名字。 为什么找不到它? 或者那是错误的types? 如果是这样,为什么intellisense暗示呢?

Angular2 TypeScript – 错误TS2307:无法find模块'angular2 / forms'

我的组件文件包含: import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: `<user></user> `, }) export class AppComponent { } 我的app.modules: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angluar/forms'; import { AppComponent } from './app.component'; import { UserComponent } from './components/user.component'; @NgModule({ imports: [ BrowserModule ,FormsModule], […]

在Sequelize中创build主键和外键关系

我有两个模型项目模型和任务模型在sequelize中定义如下所示 import { INTEGER, STRING, DATE } from 'sequelize'; import sequelize from '../sequelize'; import Task from './task.model' const ProjectModel = sequelize.define('project', { project_id: { type: INTEGER, primaryKey: true, autoIncrement: true }, phabricator_project_id: { type: STRING, allowNull: false }, name: { type: STRING }, description: { type: STRING }, start_date: { type: STRING, }, end_date: { […]

节点jsnetworking库 – 获取有关客户端(套接字)

我用socket.io使用nodejs集群,而在主线程中,我使用内置的networking库来侦听端口,并手动将连接(套接字)传递给worker(基于客户端的IP地址,所以如果客户端重新连接到服务器的客户端将join到同一个工人)。 这是行之有效的,但我想testing,我想从本地join不同的工作。 有没有什么办法获得有关客户端的信息(如浏览器名称,自定义参数)或其他任何东西,使本地主机上的两个或多个客户端不同? – 如果我能够在开发环境中将客户端join到基于浏览器的工作人员(Chrome客户端去工作人员1,Firefox客户端去工作人员2),这可能会很酷。 private createServer(): void { var self = this; this.masterServer = net.createServer(<any>{ pauseOnConnect: true }, (connection) => { console.log('server', connection); let worker = self.workers[self.getWorkerIndex(connection.remoteAddress, self.workerCount)]; worker.send('privateCon', connection); }).listen(self.serverPort); }

节点+ TypeScript:无法重新声明块范围variables“事件”

我正在将Node + ES6项目转换为TypeScript。 我瞄准ES6(因为我运行节点7.x)和使用地图。 运行tsc -p返回: src/actions.ts(3,9): error TS2451: Cannot redeclare block-scoped variable 'events' src/calendar.ts(5,10): error TS2300: Duplicate identifier 'fetchEvents'. src/index.ts(3,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'actions' must be of type 'Map<any, any>', but here has type 'any'. 不清楚为什么这些是重复的标识符或被标记为重新声明,特别是在Node的require / module导入的情况下。 在require语句中使用标准const更加严重。 calendar.ts const { rp } = require("request-promise") […]

如何发送邮件请求在Ionic 2节点服务器运行在本地主机?

在离子我用服务提供商访问http。 Service.ts文件是这样的。 数据是一个json对象。 import { Injectable } from '@angular/core'; import { Http,Headers } from '@angular/http'; import 'rxjs/add/operator/map'; @Injectable() export class Service { constructor(public http: Http) { console.log('Hello Service Provider'); } addNewPlace(data:any){ let headers = new Headers(); headers.append('Content-Type', 'application/json'); console.log(data); this.http.post("http://127.0.0.1:3000/postData/",data); } } 我的节点app.js文件是这样的 var express = require('express'); var app = express(); var bodyParser = require('body-parser'); […]

茉莉花忽略打字稿testing文件?

这是我第一次和Jasmine一起制作一个项目,我正在跟着一个教程,但马上就要解决问题了。 我已经安装了jasmine-node,typings和typescript。 我也跑了: typings install dt~jasmine –save-dev –global 为茉莉花打字稿。 现在我的./spec文件夹中有一个testing文件,如下所示: import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DatePickerComponent } from '../src/components/via-datepicker.component'; import * as moment from 'moment'; const Moment: any = (<any>moment).default || moment; describe('DatePickerComponent', () => { let component: DatePickerComponent; let fixture: ComponentFixture<DatePickerComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ DatePickerComponent ] […]

Typescript / NodeJS – 与工厂合作时的循环依赖

对于Typescript和NodeJS来说,我很新,我正尝试使用工厂在运行时创build对象。 作为一个例子,下面的对象有属性types的文本,现在在运行时得到,我想创build一个TextContainer的实例: { type: "Text", name: "Title" } 我的工厂看起来像这样: import {BaseContainer} from "../Containers/BaseContainer"; import {TextContainer} from "../Containers/TextContainer"; /** * Used to dynamically create objects with different container classes * in runtime */ export class ContainerFactory { // Object containing all class names and types private dictionary: Object; /** * Initializes factory dictionary */ constructor() { […]