Tag: typescript

如何使用Typescript + Node.js在单独的项目中创build之后安装自定义types?

我正在为四个独立的webstorm gui项目中的node.js应用程序工作。 理想情况下,我想创build一个模块插件库,其中包含一组需要由其他项目共享的代码,即GenericRepository等。我在打字稿网站上列出的文档中实现了一个模块插件; module-plugin.d.ts( https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html )。 我运行tsconfig文件编译到dist文件夹,编译成功完成。 到现在为止还挺好。 当我尝试使用“npm install –save @types /../ GenericRepository”进行安装时,例如,我收到一个错误,指出该文件夹不包含package.json文件。 这是没有意义的,因为文件夹中有一个package.json文件。 我不确定我会做错什么。 这是GenericRepository文件夹的package.json文件: { "name": "GenericRepository", "version": "1.0.0", "main": "./dist/index.js", "typings": "./dist/index.d.ts", "license": "ISC", "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": […]

TypeScript中的types问题

我有使用LoopBack和TypeScript的节点JS上的项目。 昨天,我发现这个问题: 控制台警告 我如何解决这个问题?

不能创build目录tns_modules

我在运行演示应用程序im Nativescript时遇到问题。 我运行: tns run ios 并有错误: 无法在设备上应用更改:DEVICE_ID。 错误是:处理node_modules失败。 错误:cp:无法创build目录“/ workspace / demo / platforms / ios / demo / app / tns_modules”:没有这样的文件或目录。 我究竟做错了什么?

如何解决nest.js中的DI问题?

我想了解如何通过DI在nestjs中导入第三方库。 所以,我有一个类AuthService : export class AuthService { constructor( @Inject(constants.JWT) private jsonWebToken: any, ){} …. } 智威汤逊提供商: import * as jwt from 'jsonwebtoken'; import {Module} from '@nestjs/common'; import constants from '../../../constants'; const jwtProvider = { provide: constants.JWT, useValue: jwt, }; @Module({ components: [jwtProvider], }) export class JWTProvider {} 库模块: import { Module } from '@nestjs/common'; import […]

HTTPerror handling在低networking区域获取数据

嘿家伙我使用离子3本地HTTP做HTTP请求到我的后端服务器,我注意到在低信号区域的一些HTTP请求进入HTTP请求的error handling程序,因为它不能发送请求,由于networking信号低。 我想知道是否有任何人有build议或经验,如果它是一个好主意尝试重试error handling程序的HTTP请求,以便它可以再次尝试,看看它是否可以尝试再次发送请求? 如果是的话,你是如何正确处理这个问题的? 只是想看看如何使我的离子3应用程序在低信号区域更稳定。

Web的简单通用Visual Studio 2017项目模板

我正在Visual Studio中使用外部工具(如angular色cli或webpack)开发简单的网站。 这似乎并不像是有一个适当的项目模板。 我不需要像nodejs或asp.net项目提供的特殊的东西。 我只是想能够定义我自己的行动,没有别的。 我想要的是: 简单的项目结构显示文件(就像正常,但没有列出NPM包) configuration,如debugging/发布 在build / rebuild / start等上运行自己的脚本(取决于configuration) 我知道这可以使用vs代码来完成。 但vs2017提供了我所需要的许多function。 有什么办法可以在VS2017中做到这一点? 如果没有,是否可以写一个自己的项目模板呢?

用JStesting文件testing用Karma和Jasmine编译的TypeScript

我有一个具有以下结构的项目: build – out.js spec – foo.spec.js – bar.spec.js src – foo.ts – bar.ts 这两个.ts文件被构build到out.js 。 在我的.spec.js文件中,我希望能够轻松地引用out.js 当在纯JS项目中使用Karma / Jasmine时,我只需要使用RequireJS,并将我的testing文件封装在define(['a'], function(a) { … }); 文件。 然后,在a.js ,内容将如此包装: define([], function() { Foo.prototype. ……. Foo.prototype. ……. return Foo; }); 但是,由于out.js将由TypeScript编译器构build,因此无法封装在define(…)块中,因此无法使用RequireJS正确导入它。 澄清: 用下面的手写JS,我可以把它导入到我的testing文件中: define([], function() { function Bla() { } Bla.prototype.hi = function () { return "hey"; }; […]

无法在NodeJS中使用Mongoose和Typescript扩展基类

我正在尝试使用Mongoose 4.5.4, 它在使用Typescript(显然)的NodeJS中使用Repository模式进行打样。 RepositoryBase: export class RepositoryBase<T extends mongoose.Document> implements IRead<T>, IWrite<T> { private _model: mongoose.Model<mongoose.Document>; constructor(schemaModel: mongoose.Model<mongoose.Document>) { this._model = schemaModel; } create(item: T): mongoose.Promise<mongoose.model<T>> { return this._model.create(item); } //…… //Additional CRUD methods excluded for brevity } UserRepository: export class UserRepository extends RepositoryBase<IUserModel> { constructor() { super(UserSchema); } } 我从UserRepository调用super()时UserRepository以下types的错误 [ts] Argument of type […]

带有打印机&mongoose的静态方法会:“一个接口只能扩展一个类或另一个接口”。

我尝试添加一个静态方法到我的模型,但如果我这样做,我得到这个错误: An interface may only extend a class or another interface. 这是我的代码: import * as mongoose from 'mongoose'; import {IPermission} from './IPermission'; export interface IRoleDocument extends mongoose.Document { name: string, inherit_from: { type: mongoose.Schema.Types.ObjectId, ref: 'Role' }, permissions: Array<IPermission> }; export interface IRole extends mongoose.Model<IRoleDocument> { }; 错误来自export interface IRole extends mongoose.Model<IRoleDocument> 格尔茨

运行用TypeScript编写的Jasminetesting

我有一个TypeScript + Node + Angular2 + Electron应用程序,目前正在尝试运行节点类的testing,也写在Typescript中。 为了构build应用程序并在电子内运行,我使用下面的tsconfig: "compilerOptions": { "module": "system", "target": "es6", … } 正如你所看到的,它使用了systemjs并将TS编译成JS-es6。 它工作正常,应用程序本身正在工作。 现在我需要茉莉花来join 我安装了这个npm包,更新了我的gulp任务,运行gulp-jasmine只有一个文件: gulp.task('jasmine', function() { gulp.src('./test/test.js') .pipe(jasmine()) }); 这是我的test.js的样子: System.register(["./models-src/app/models/pathWatch/pathWatch"], function(exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var pathWatch_1; return { setters:[ function (pathWatch_1_1) { pathWatch_1 = pathWatch_1_1; }], execute: function() { describe("Run […]