Tag: 打字稿

文件之间的NodeJs TypeScript命名空间

我正在使用typescript 2.4.2与节点v6.11.2。 我来自.net世界,并试图了解如何安排我的代码与打字机的节点。 我以这种方式在代码中定义了命名空间: hirarchy: src index.ts —–DataModel —————-Customer.ts —————-Employee.ts 客户类别: Customer.ts : export namespace DataModel { export class Customer { } } 雇员类: Employee.ts export namespace DataModel { export class Employee { } } 在其他文件中使用DataModel命名空间中的类的方法是什么? index.ts是这样的: //import row . DataModels.Employee DataModels.Customer

在节点js的打字稿中获取os环境

我有称为KEY的操作系统环境,当我在Ubuntu中与echo $KEY调用它,它将打印出的值 如何在打字稿中获得这个值? 我已经find了这个,每一个说我必须在我的打字稿代码中调用process.env.KEY ,但是如果我打印process.env.KEY它会打印undefined

离子 – 关于版本的困惑

这是我的客户端package.json : { "name": "ionic-hello-world", "author": "Ionic Framework", "homepage": "http://ionicframework.com/", "private": true, "scripts": { "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts build", "ionic:build": "ionic-app-scripts build", "ionic:serve": "ionic-app-scripts serve" }, "dependencies": { "@angular/animations": "^4.1.3", "@angular/common": "4.1.3", "@angular/compiler": "4.1.3", "@angular/compiler-cli": "4.1.3", "@angular/core": "4.1.3", "@angular/forms": "4.1.3", "@angular/http": "4.1.3", "@angular/platform-browser": "4.1.3", "@angular/platform-browser-dynamic": "4.1.3", "@angular/platform-server": "4.1.3", "@ionic-native/core": "3.12.1", "@ionic-native/device": "^3.12.1", "@ionic-native/file-opener": "^3.12.1", […]

打字稿丢失信息模块加载w /没有.dts文件

我遇到了一个问题,即在使用Typescript而不是JavaScript时出现错误或丢失types信息。 下面的使用VS Code的“JS”代码实际上给了我有关正在导入的bitcorevariables的信息。 但是当使用Typescript时,导入的bitcorevariables会给出一个错误,说明它缺less一个定义文件,如果我使用var而不是import来引入模块,那么我只是得到一个“any”types的variables。 鉴于这是Typescript,我应该能够获得至less与Javascript可以的types信息。 编辑:我发现一个令人困惑的,隐藏的“function”的TS /代码,如果没有tsconfig.json存在,并且types进来作为“任何”,该types的信息是合法地find另一个打开的文件VS Code工作区,在这种情况下是一个JavaScript文件,那么它将在VS Code工作区中“caching”该types的信息,并将其显示在.ts文件中,即使TS本身并没有获取该信息。 TS import bitcore = require("bitcore-lib") var key = new bitcore.PrivateKey("testnet") console.log(key) JS var bitcore = require("bitcore-lib"); var key = new bitcore.PrivateKey("testnet"); console.log(key); TS w /没有tsconfig.json目前和types信息已经从“caching”检索后,打开一个不同的JavaScript文件,检索到types信息。

如何在构成angular4项目的父目录中引用node_modules

我不太会说英语。 我当前的目录configuration Project ├ node_modules ├ packages │ ├ product │ │ ├ dashboard => don't have "node_modules" directory │ │ │ ├ package.json │ │ │ … │ │ … │ … ├ package.json … 和仪表板目录package.json { "scripts": { "ng": "ng", "start": "ng serve –dev –hmr –port 8460 -pc proxy.conf.js", "build": "ng build –prod […]

如何扩展nodejs模块的打字稿定义

我使用nodejs模块“ws”,并安装types我dt〜ws import * as WebSocket from "ws"; function add(client:WebScoket){ let cid = client.clientId; } 我想扩展 WebSocket属性clientId ,但我不知道如何。 我已经尝试在我的定义文件index.d.ts编写跟随代码 declare module "ws" { class WebSocket { ip: string; clientId: number; project: string; } } 但效果不好

find()结果到数组,但不使用.filter的node.js mongodb

我试图从mongodb.find()返回结果使用Array.filter() mongodb.find() ,但它不工作! 我得到这个错误: (TS)属性“filter”在types“{}”上不存在。 function find(collectionName: string, filter: any = {},callback: Function) { const MongoClient = require('mongodb').MongoClient; let url = "mongodb://localhost:27017/test"; MongoClient.connect(url, function (err, db) { if (err) { callback(err, null); //throw err; db.close(); } else { let rs = db.collection(collectionName).find(filter, { _id: false }); rs.toArray(function (err, result) { if (err) throw err; callback(null, […]

在打字稿中访问Nodejsstream的highWaterMark属性给出:“Property'_readableState'不存在”错误

我的问题是关于nodejs中的打字稿和stream。 我不想扩展stream基类,并访问highWaterMark选项。 在打字稿中,以下代码起作用(即打印highWaterMark选项) import * as stream from 'stream'; class ExampleStream extends stream.Readable { constructor() { super(options) console.log(this._readableState.highWaterMark) } _read() {} _write() {} } 但打字稿给我关于这一行的以下错误信息: console.log(this._readableState.highWaterMark) ['ts]types'ExampleStream'上不存在'_readableState'属性。 我如何解决这个问题?

angular2嵌套路由不工作,没有错误报告,但空白页

请帮我检查一下代码…没有编译错误,否则在npm start后cli输出,但浏览器看起来是一个空白页面。 我一遍又一遍地检查,但仍然找不到有什么问题。 PS:我是一个新生在angular2 … app.module @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AdminModule, WaiterModule, CookModule, AppRoutingModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } APP-routing.module const appRoutes: Routes = [ { path: "", redirectTo: "/admin", pathMatch:"full" } ]; @NgModule({ imports: [ RouterModule.forRoot(appRoutes, { enableTracing: true }) ], exports: [RouterModule] }) […]

如何在Mongoose.js模式中表示ES6映射

我正在使用ES6 Map作为“specs”属性,我已经在下面的TypeScript接口中表示了这一点: import { IModel } from './model'; export interface IProduct extends IModel { name: string; description: string; specs: {[key: string]: string }; img: string[]; } 不过,这似乎并不适用于mongoose模式。 之后,失败了,我试图在我的模式下面的代码,这似乎不工作: const ProductSchema = new Schema({ name: String, description: String, specs: [{key: String, value: String}], img: String[] }); 如果有人能帮我找出正确的方法来做到这一点,我将非常感激。