Tag: 打字稿

为什么在使用shell时,javascript ssh2会陷入无限循环

我试图让我的应用程序通过使用ssh2 npm包在另一个系统上执行sudo命令。 我有最终的结果工作,但由于某种原因,代码陷入了一个无限循环。 我不明白这是如何可能的,因为我认为用conn.endclosures连接会防止这种情况发生。 任何人都可以帮助解释为什么我在这里陷入无限循环? 正在执行的主要代码: function sshRunSudoCommand(user, pass, lanIP, command) { return new Promise((resolve, reject) => { var Connection = require('ssh2'); var pwSent = false; var sudosu = false; var password = pass; var conn = new Connection(); conn.on('ready', function() { console.log('Sudo Connection :: ready'); conn.shell( function(err, stream) { if (err) throw err; stream […]

testing失败:ReferenceError:SpeechSynthesisUtterance未定义

我最近试图在我的项目中实现文本到Speech,并决定使用纯javascript的解决scheme。 ( https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance ) 我目前使用React@15.4.2和enzyme@2.9.1。 码: export default class DummyComponent extends React.Component { /* */ speak(text) { var synth = window.speechSynthesis; var utterThis = new SpeechSynthesisUtterance(text); synth.speak(utterThis); } /* */ } 一切工作正常,但每当我尝试testing我的代码,我得到的标题中的错误。 ExampleTest: it('dummytest', function(done){ const prop1 = 'foo'; const prop2 = 'bar'; const wrapper = shallow(<DummyComponent prop1 = {foo} prop2={bar}/>); expect(wrapper.html()).to.include("foobar"); done(); }); ReferenceError:SpeechSynthesisUtterance未定义 […]

search查询angular度4restAPI

我遵循的教程工作: https : //alligator.io/angular/real-time-search-angular-rxjs/我需要改变我的应用程序的一些信息,但无法正常工作。 按照代码:组件: export class SearchComponent implements OnInit { articlePosts; results: Object; searchTerm$ = new Subject<string>(); constructor( private searchService: SearchService, private authService: AuthService ) { this.searchService.search(this.searchTerm$) .subscribe(results => { this.articlePosts = results.articles; }); } } 服务: export class SearchService { options; domain = this.authService.domain; queryUrl: string = '?search='; constructor( private authService: AuthService, private […]

Angular 4 – Http到HttpClient – 属性'someproperty'在Objecttypes上不存在

我试图改变现有的应用程序使用Http使用HttpClient ,但是我有一个错误。 因此,在我的服务中,您可以看到新代码与已被注释掉的旧代码: constructor( // private http: Http private http: HttpClient ) { } getSidebar() { // return this.http.get('http://localhost:3000/sidebar/edit-sidebar') // .map(res => res.json()); return this.http.get('http://localhost:3000/sidebar/edit-sidebar'); } 而在我的page.component.ts我有这个 this.sidebarService.getSidebar().subscribe(sidebar => { this.sidebar = sidebar.content; // this does not work now }); 然而,对于上面我评论的行我现在得到这个错误: Property 'content' does not exist on type 'Object'. 但是,如果我console.log(sidebar)我得到以下内容: {_id: "59dde326c7590a27a033fdec", content: "<h1>sidebar here</h1>"} […]

用于angular度2/4项目的自定义日志文件

我需要添加一个日志文件到我的angular2项目存储信息,错误日志文件如log.txt文件如何创build服务,创build和写入日志文件使用打字稿

DefinitelyTyped如何将声明文件绑定到JavaScript库?

我想知道如何将DefinitelyTyped每个声明types绑定到其相关的JavaScript库。 例如@type/lodash如何链接到js库lodash ? 手册指出我们可以在npm包中的package.json中添加一个"type"标记,但是在search了几个JavaScript组件(包括angular , ace等)之后我没有看到。 精通TypeScript的人能告诉我这个窍门吗? 谢谢!

如何使节点线阅读器有条件地跳过线

我目前正在使用一个在线阅读器将信用卡号码inputvalidation器和标识符的项目。 比方说,我input10个数字,他们来自四个不同的信用卡公司。 我想忽略三家公司,只显示其余公司的数字。 这个公司的规则(条件)是它必须有15个数字,并且从37或34开始 4111111111111111 4111111111111 4012888888881881 378282246310005 6011111111111117 5105105105105100 5105105105105106 9111111111111111 371449635398431 378734493671000 这是我目前的临时模块: export const isAmex = (creditCard: string): boolean => creditCard.length === 15 && (creditCard.substring(0, 2) === '37' || creditCard.substring(0, 2) === '34') export const is2Amex = (creditCard: string): boolean => creditCard.length === 15 && (creditCard.substring(0, 2) === '37' || creditCard.substring(0, 2) […]

如何在JavaScript中使用types没有打字稿?

我GOOGLE了这个问题,但发现答案有点混乱。 我最近受雇成为nodejs开发者。 我在过去的几年里一直是Java开发人员。 林有点担心写nodejs和没有types。 但是与此同时,我想以与团队中其他人一样的方式编写代码,所以我不想使用打字稿,同时我也不想成为那个进入新团队的人就像试图让每个人改变自己的事情。 所以我的问题是。 有没有办法写nodejs,所以我得到types。 就像我创build一个JavaScript类 function Apple (type) { this.type = type; this.color = "red"; this.getInfo = getAppleInfo; } 然后我用它 var apple = new Apple('macintosh'); apple.color = "reddish"; alert(apple.getInfo()); 当我写“苹果”。 我想Webstorm或Atom知道有一个types,颜色和getInfo()函数可用。 这在某种程度上可能吗?

具有Sequelize和Typescript的外键

鉴于这2个Sequelize模型: export class Users extends Model<Users> { @HasMany(() => UserRoles) @Column({ primaryKey: true, allowNull: false, unique: true }) UserId: string; @Column({ allowNull: false, unique: true }) Email: string; } export class UserRoles extends Model<UserRoles> { @ForeignKey(() => Users) @Column({ primaryKey: true, allowNull: false, unique: true }) UserId: string; @Column({ allowNull: false }) RoleId: number; } […]

从TypeScript Firebase Admin SDK初始化失败

我正在尝试在我的TypeScript(Nest.js)应用程序中导入Firebase Admin SDK。 let serviceAccount = require("../../creds.json"); console.log(serviceAccount); const firebase = require("firebase"); firebase.initializeApp(environment.firebase); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "projectid" }); 但是当我尝试构build应用程序时,出现以下错误。 ERROR in ./node_modules/@google-cloud/firestore/src/v1beta1/firestore_client.js Module not found: Error: Can't resolve './firestore_client_config' in '/home/jaybell/trellis-server/trellis/node_modules/@google-cloud/firestore/src/v1beta1' @ ./node_modules/@google-cloud/firestore/src/v1beta1/firestore_client.js 28:17-53 @ ./node_modules/@google-cloud/firestore/src/v1beta1/index.js @ ./node_modules/@google-cloud/firestore/src/index.js @ ./src/server/main.server.ts ERROR in ./node_modules/google-gax/lib/operations_client.js Module not found: Error: Can't resolve './operations_client_config' in '/home/jaybell/trellis-server/trellis/node_modules/google-gax/lib' @ ./node_modules/google-gax/lib/operations_client.js […]