Tag: 打字稿

将“this”传递给构造函数中的类variables

我感兴趣,如何将其传递给父类的构造函数中的类variables,所以我可以使用父类方法并访问父类的其他variables并调用它们的方法? 这是我的父类: var async = require('async'); var Rater = require('./rater') var Similars = require('./similars') var Suggestions = require('./suggestions'); module.exports = class Engine { constructor() { this.likes = new Rater(this,'likes'); this.dislikes = new Rater(this,'dislikes'); this.similars = new Similars(this); this.suggestions = new Suggestions(this); } 这里是使用的例子,并在哪里得到以下错误: Cannot read property 'engine' of undefined at –\\classes\rater.js:89:19 module.exports = class Rater […]

在打字稿中找不到'autobind-decorator'的声明文件

我正在使用Typescript,我想在项目中导入'autobind-decorator'包,但我卡在这里。 编译时出现这个错误行: 找不到“autobind-decorator”的声明文件。 隐含有一个“任何”types 我也试过@types/autobind-decorator npm包,但是没有成功。 有没有select摆脱这个编译错误? 这是我的tsconfig: { "version": "2.1.5", "compilerOptions": { "module": "commonjs", "lib": ["es2015", "es2016", "dom"], "sourceMap": true, "noImplicitAny": true, "target": "es6", "jsx": "react", "skipLibCheck": true, "experimentalDecorators": true }, "include": [ "./packages/ld-web/src/**/*" ], "exclude": [ "**/node_modules", "**/*.d.ts" ] } 导入: import * as autobind from "autobind-decorator";

属性'body'在types'Request'上不存在

请求types的reqvariables对于属性主体没有智能感知 。 这是由于types? import { Request, Response } from 'express' import { ok, bad } from './responses' export const signIn: async (req: Request, res: Response) => { try { const { name, pword } = req.body // body is not recognized const data = auth.signIn(name, password) ok(res, data) } catch (error) { bad(res, error) } […]

“后续的variables声明必须具有相同的types”

我正在关注这个链接,使用webworker-thread启动一个示例节点js项目。 https://www.npmjs.com/package/webworker-threads 这里是我的ts代码: var Worker = require('webworker-threads').Worker; // var w = new Worker('worker.js'); // Standard API // You may also pass in a function: var worker = new Worker(function(){ postMessage("I'm working before postMessage('ali')."); this.onmessage = function(event) { postMessage('Hi ' + event.data); self.close(); }; }); worker.onmessage = function(event) { console.log("Worker said : " + event.data); }; […]

将Json数据从服务器存储到Angular 2中的数组中

我使用nodejs服务器从SQL数据库中获取数据。 我会将数据存储在Tache数组中: getTaches(): Observable<Tache[]> { return this.http.get(this.tachesUrl) .map(response => { this.taches = response.json().data as Tache[]; console.log(this.taches); }) .catch(this.handleError); } 当我在控制台上打印时,我得到的结果如下: undefined 当我打印response.json()我得到我的价值观: Object {taches: Array(8)} 所以我删除.data,然后再试一次,然后我在模板文件的第一行得到另一个错误: ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed 这是我的html文件: <md-toolbar color="primary"> <span>Taches non traitées</span> </md-toolbar> <md-card> <md-list > <ng-container *ngFor="let tache of this.tacheService.taches […]

BigNumber的TypeScripttypes定义

我正在尝试在TypeScript程序中使用BigNumber版本4.0.2。 我创build了一个用TypeScript编写的简单Node.js程序的简化示例,该示例使用BigNumber来处理此问题https://github.com/naddison36/node-imports 我真的很努力得到TypeScript 2.3.4拉入BigNumber的types定义。 有谁知道如何做到这一点? 这是我迄今为止所尝试的https://github.com/naddison36/node-imports#attempts-to-get-the-bignumber-type-definitions-to-work 理想情况下,我想简单地运行npm install bignumber.js –save , npm install @types/bignumber.js –save ,使用ES6 import BigNumber from 'bignumber.js' TypeScript正常工作。 任何帮助,将不胜感激

TypeScript readline.createInterface引发exception

我正在尝试创build一个电子应用程序。 在main.ts中我构build了我认为是相当简单的类(下面),但是构造函数不会运行。 对readline.createInterface(inputStream)的调用失败。 看来运行时并不认为调用fs.createReadStream返回的variables有一个名为'on'的函数。 例外是 Uncaught Exception: TypeError: Cannot read property 'on' of undefined at new Interface (readline.js:142:10) at Object.exports.createInterface (readline.js:28:10) at new FileMonitor (/Users/mikedice/code/electron-rm/app/FileMonitor.js:13:38) at App.Main.onReady (/Users/mikedice/code/electron-rm/app/Main.js:27:23) at emitTwo (events.js:111:20) at App.emit (events.js:191:7) 这是生成它的代码块。 import readline = require("readline"); import fs = require("fs"); export class FileMonitor { constructor(public filePath:string){ if (!fs.existsSync(filePath)){ console.log(`file does not exist […]

npm ERR! 无效的名称:“@ types / handlebars”

我试图用npm安装typedoc,但是看到下面的错误: npm ERR! Invalid name: "@types/handlebars" 然后我试图直接安装@ types / handlebars: npm install @types/handlebars 并再次显示相同的错误消息。 当我尝试通过运行查看包信息时: npm info @types/handlebars 我可以正确地看到信息。 我还应该检查什么来解决这个问题? 我在OSX 10.10.5上使用节点v4.8.3和npm v2.15.11。 这里是npm-debug.log的堆栈跟踪: 58 verbose etag https://registry.npmjs.org/@types%2fhandlebars from cache 59 verbose get saving @types/handlebars to /Users/ycchen/.npm/registry.npmjs.org/_40types_252fhandlebars/.cache.json 60 verbose correctMkdir /Users/ycchen/.npm correctMkdir not in flight; initializing 61 silly addNameTag next cb for @types/handlebars with tag […]

如何从其他js文件扩展类而不需要声明文件

第三个Javascript Lib // publish at npm event-emitter export default class EventEmitter{ emit(){ // do something } on(){ // do something } } 打字稿文件 import EventEmitter from 'event-emitter'; class Http extends EventEmitter{ constructor() { super(); this.emit(); // error TS2339: Property 'emit' does not exist on type 'Http' } } 错误TS2339:属性'emit'在types'Http'上不存在 问题是:如果它没有index.d.ts文件,如何扩展这个类? 我用webpackbuild立这个 当我build立成功。 我发现从事件发射器导入eventEmitter; 相等未定义。

stripe angular错误:Uncaught(在promise中):TypeError:无法读取未定义的属性'stripeService'

我目前正在尝试实现条纹到我的angular4 nodejs应用程序,但我有点卡住了,当我试图通过我的服务发送卡令牌到我的服务器处理与条带相关的请求。 这是我得到的代码: stripe.component.html: <form role="form" id="payment-form"> <div id="card-element"></div> <div id="card-errors" role="alert"></div> <button type="submit" (click)="addCard()">Submit Payment</button> </form> stripe.component.ts: import {Component, OnInit} from "@angular/core"; import {WindowRef} from "../social/windowRef"; import {StripeService} from "./stripe.service"; @Component({ selector: "app-stripe", templateUrl: './stripe.component.html', styleUrls: ['./stripe.component.css'] }) export class StripeComponent implements OnInit { elements: any; stripe: any; style: any; card: any; constructor(private stripeService: […]