Tag: 打字稿

如何在一个项目中设置Angular 2,Node(Hapi.js)和TypeScript?

我想设置Angular 2(TypeScript)和节点(带有TypeScript的Hapi.js)项目。 你可以给我一步一步教程如何组织和设置我的项目? 我知道如何在其中一个项目中安装Angular 2(TypeScript),并在其他项目中使用Node(Hapi.js和TypeScript),但是我在合并客户端和服务器端时出现问题。 我有多种types的问题,加载模块,不同的tsconfigs,加载网页上的库,文件夹结构,… 据我所知,SystemJS和Webpack是相同的东西,他们被用来准备JS文件在网页上使用它。 这是正确的,如果是你会select哪一个(也可以在教程中提供项目设置)? 另外,我想知道是使用Gulp或Grunt是有用的,哪里将在这些技术的项目设置? 总结哪些技术堆栈最适合使用TypeScript开发Angular 2和Node(Hapi.js)应用程序,以及如何设置它们?

找不到“节点”的types定义文件

更新angular,webpack和typescript后,我得到奇怪的错误。 任何想法,我可能会错过? 当我用npm开始运行应用程序时,我得到以下错误: [at-loader] Cannot find type definition file for 'hammerjs'. [at-loader] Cannot find type definition file for 'node'. [at-loader] src\app\app.component.ts:26:14 Cannot find name 'require'. [at-loader] src\app\app.component.ts:30:15 Cannot find name 'require'. 这里是依赖关系: "dependencies": { "@angular/common": "2.4.4", "@angular/compiler": "2.4.4", "@angular/core": "2.4.4", "@angular/forms": "2.4.4", "@angular/http": "2.4.4", "@angular/material": "2.0.0-beta.1", "@angular/platform-browser": "2.4.4", "@angular/platform-browser-dynamic": "2.4.4", "@angular/platform-server": "2.4.4", "@angular/router": "3.4.4", "@angularclass/conventions-loader": […]

如何在TypeScript中正确地要求和声明节点库types?

我正在尝试使用标准节点库(例如fs , path , stream , http在TypeScript中为节点编写一个包。 当我尝试在.ts文件中导入库时,VS Code标记相应的行并出现错误: [ts] Cannot find module 'fs' 。 无论如何尝试导入库,都会发生这种情况: import * as fs from 'fs'; // [ts] Cannot find module 'fs' import fs = require('fs'); // [ts] Cannot find module 'fs' const fs = require('fs'); // [ts] Cannot find name 'require' 我(应该)有安装正确的定义安装 – typings install –save –ambient node […]

WebStorm tsconfig.json似乎不更新正确的文件

我正在开发使用TypeScript的node.js应用程序。 我在我的项目的根文件夹中创build了一个TypeScript文件。 我运行tsconfig ,它似乎更新dist文件夹。 但是,当我运行的应用程序,我收到一个错误,指出一个函数没有定义。 这里是令人困惑的地方:我的src文件夹中的.js和.map文件的老版本似乎与我的源文件具有相同的名称。 这个.js文件似乎有一个较旧版本的文件,缺less必要的function(类方法),与我/dist文件夹中的当前版本不同。 在这一天结束的时候,我试图在我的/dist文件夹中的文件上运行debugging器,并在我的/src TypeScript文件中设置断点。 这是我在/src文件夹中看到的文件结构的样本(这个js文件不是最新的): 下面是我的/dist文件夹的结构js代码所在的文件结构的例子: 此外,这里是项目的Web应用程序(rest)部分的debugging器设置: 最后,这是一个tsconfig.json文件的示例: { "compilerOptions": { "module": "commonjs", "target": "ES5", "moduleResolution": "node", "experimentalDecorators": true, "emitDecoratorMetadata": true, "types": ["reflect-metadata"], "lib": ["ES6"], "sourceMap": true, "inlineSources": true, "pretty": true, "outDir": "./dist", "rootDir": "./src/", "noLib": false }, "compileOnSave": true, "include": [ "src/**/*" ], "exclude": [ "node_modules", "node_modules/@types" ] } […]

打包一个nodejs c ++共享库

我做了一个nodejs共享库,现在我想打包它来部署它。 我希望能够与包装的angular2应用程序使用它感谢webpack。 共享库位于build / Release文件夹中。 如何继续在webpack中很好地打包? 或者是一个特定的package.json声明? 看看nodejs文档,dll名称使用扩展名.node( https://nodejs.org/api/addons.html#addons_loading_addons_using_require ) webpack节点加载器可能有帮助吗? https://webpack.js.org/loaders/node-loader/ 我将使用服务器端渲染,否则这将是不可能的。 问候,Steph

如何安装自定义types?

我创build了一个自定义的input包含代码,我想分享几个webstorm node.js项目。 问题是,我正在试图find文件,概述如何在项目中包含input。 我尝试使用npm命令,但没有将该文件夹添加到/ node_modules文件夹下的@typings文件夹中。 此外,当我编译项目,我试图添加自定义打字,我在包含打字的项目和我想添加打字的项目之间的mongoose库重复错误。 我不确定问题可能是什么。 tsconfig.json(对于新types): { "name": "newcustomtype", "description": "…", "version": "1.0.0", "main": "./dist/index.js", "typings": "./dist/index.d.ts", "scripts": { "grunt": "grunt" }, "dependencies": { "@types/express": "^4.0.35", "@types/express-jwt": "0.0.34", "debug": "^2.2.0", "dotenv": "^4.0.0", "mongoose": "^4.9.2", "tslint": "^4.5.1" }, "devDependencies": { "@types/mongodb": "^2.1.41", "@types/mongoose": "^4.7.9", "@types/node": "^7.0.10", "grunt": "^1.0.1", "grunt-cli": "^1.2.0", "grunt-contrib-watch": "^1.0.0", "grunt-ts": "^6.0.0-beta.15", […]

使用module = system为节点设置TypeScript不起作用

我试图设置使用打字稿的restify项目。 经过各种尝试后,我可以通过在tsconfig.json中使用“module:commonjs”创build一个工作版本 我宁愿使用系统 – 但我不能用systemjs来设置它 boot.ts import {AppServer} from './app'; var _appServer = new AppServer(); tsconfig.json { "compilerOptions": { "target": "ES5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false }, "exclude": [ "node_modules" ] } app.ts /// <reference path="typings/restify/restify.d.ts" /> import {Server, Response, Request, createServer} from 'restify'; export class […]

Aurelia应用程序“Hello World”根本不工作

我正在创build一个Sharepoint框架webpart,我正在尝试使用Aurelia作为我的JavaScript框架。 基本上我创build了一个Sharepoint框架webpart,当用Yeoman创build时,创build这个文件夹结构 。 然后我的文件(只是一个简单的问候世界): app.html <template> ${message} </template> app.js export class App { message = 'hello world'; } main.ts import {Aurelia} from 'aurelia-framework'; export function configure(aurelia) { aurelia.use .standardConfiguration() .developmentLogging(); aurelia.start().then(a => a.setRoot()); } 的index.html <div aurelia-app> <h1>Loading…</h1> <h2> ftw </h2> <script src="jspm_packages/system.js"></script> <script src="config.js"></script> <script> System.import('aurelia-bootstrapper'); </script> </div> 和helloworld webpart: import { BaseClientSideWebPart, IPropertyPaneSettings, […]

es6模块到commonjs节点和谐旗下的打字稿

我在–harmony标志下使用TypeScript(1.6),所以我想将es6模块语法转换为commonjs。 从我可以告诉,我不能用TypeScript 1.6做到这一点。 如果我将目标设置为es6,并将模块设置为commonjs,则会出现TypeScript错误 – 定位“ES6”或更高版本时,无法将模块编译为“commonjs”,“amd”,“system”或“umd”。 为什么不将TypeScript编译成commonjs与ES6目标? 我想很多人都希望这样做,因为节点还不支持ES6模块。 我以为新的moduleResolution编译器选项可能会解决这个问题,但它似乎没有做任何事情。 目前,我不得不使用babel来将模块语法转换为commonjs,但是我想从构build中删除babel,这样我就可以利用源映射。 有什么办法可以做到这一点? 注意:我不想传输到ES5。 我希望我的JS在和谐标志下作为ES6运行。 谢谢!

部署打字稿NodeJS服务器

将TypeScript中编写的NodeJS服务器部署到生产中的最佳实践是什么? 我想避免在我的git仓库中有每个脚本的3个文件(ts,js,map)。 我可以使用grunt / gulp来创build“dist”目录,并将所有编译的文件复制到那里,但是反过来我也会把它们放在我的repo中。 我可以为编译的代码创build单独的回购,但是这并不理想,我想。 另外,当我运行没有js或map的node app.ts时,它实际上启动了一切正常。 那么编译的文件甚至需要节点服务器吗? 注意:我没有任何编译脚本/任务,我的IDE正在为我自动编译ts文件。