Tag: typescript

使用TypeScript的variables参数 – 强制最后一个参数

假设我们有一个接受可变数量参数的函数,我相信它被称为可变参数函数。 像这样的东西: function foo(){ let args = Array.from(arguments).map(v => whatever); // do something with args } 此函数的TypeScript接口可能如下所示: interface IVariadicFn { (…args: string[]): void, } 但是让我们说我们期望可变数量的string,但最终的参数,我们希望是一个callback函数。 所以我们有这样的东西: function variadic(){ let args = Array.from(arguments) let fn = args.pop(); let $args = args.map(v => whatever); // do something with args process.nextTick(function(){ fn(null, $args); // fire the callback, asynchronously […]

使用导入时,TypeScript将不会parsing模块

// Modules/MyModule.ts ——————————– import fs = require("fs"); module Hello { export function World(): string { return "Hello World"; } } // Main/App.ts —————————————- console.log(Hello.World()); // Cannot find name 'Hello' 出于某种原因,这会产生上面指定的错误。 奇怪的是,如果我取消注释导入声明,我不会得到这个错误了。 (反正没用过) 两者都产生相同的错误: tsc Main/App.ts –module "commonjs" tsc Main/App.ts –module "amd" 这真的是一个编译器错误,或者我错过了一些东西。 我是否需要指定外部模块需要不同?

如何从Visual Studio Code API打开浏览器

我正在探索一种方法,以便从用于开发扩展的Visual Studio Code API中打开默认浏览器。 以下是我的代码: var disposable = vscode.commands.registerCommand('extension.browser', () => { // The code you place here will be executed every time your command is executed vscode.Uri.call("http://facebook.com"); }); 如何使用vscode类从API打开浏览器URL。

如何处理承诺,因为他们解决?

目前,这个代码打印出一个零,因为数组中的第一个承诺立即解决。 const promises = []; const promiser = (number) => new Promise((resolve, reject) => window.setTimeout(() => resolve(number), number * 100)); for (let index = 0; index < 10; index++) { const promise = promiser(index); promises.push(promise); } Promise.race(promises).then(r => console.debug(r)); 我期待这样做,以便一旦最快的承诺解决,它是从promises数组中删除和一个新的Promise.race调用剩下的承诺,重复,直到没有承诺离开。 由于Promise.race返回的是承诺的结果,而不是解决的承诺本身,但是,我无法确定哪个承诺是解决的,我不知道哪一个从数组中删除。 有没有办法知道这个? 我想我可以用某种相关键和结果返回一个复杂的对象,但这似乎很奇怪。 我希望Promise.racecallback的第二个参数将是承诺的索引,但事实并非如此,因为then只是另一个承诺的一个,所以它怎么会知道它应该无论如何返回一些索引。 你能想出更好的办法吗? 而且,我在第一race执行了所有的承诺,但是这对后来的race来说应该不成问题,对吗? 如果在接下来的race之前另一个承诺解决了,那么应该把它退还,没问题,对吗? 如果同时有多个承诺解决,它只会返回第一个(按照数组顺序或按照分辨率顺序?),然后下一个race将返回第二个,依此类推…对吗? 顺便说一句,我也尽pipe我可以走arrays,并删除已经isResolved承诺,但这不是一个真实的事情。 即使是这样,但是对于race诉求之间的多重承诺解决的情况来说,这完全是race 。

使用节点提取时,不能调用其types缺less调用签名的expression式

我试图让我的脚本工程中的node-fetch工作: import * as fetch from 'node-fetch'; import * as assert from 'assert'; export class DatabaseConfigurator { private url: string; getNode (): Promise<string> { return fetch(`${this.url}/_membership`).then((response: fetch.Response) => { return response.json(); }).then((res: any) => { assert.equal(res.all_nodes.length, 1); return res.all_nodes[0]; }); } } 我得到: Cannot invoke an expression whose type lacks a call signature. Type 'typeof […]

节点typescript客户端debugging

是可以从Visual Studio(2015)直接debugging(断点,手表) 客户端 .ts打字稿文件? 我发现在谷歌和stackoverflow的大部分相关问题build议使用其他浏览器devtools如铬。 是否有可能在视觉工作室做到这一点? 当我创build一个.ts脚本(比如说index.ts)时,它将被转换成一个index.js,然后这个脚本标记中的index.html文件将被引用。 如何在.ts文件中设置断点(虽然它是被引用的.js)?

Angular2&SystemJS:在构buildmoduleLoader时找不到模块

什么是上下文? 我正在使用SystemJS,Angular2和@ ngrx / store开展一个项目。 目前,我试图做一个简单的模块加载器。 它运作良好。 这是事情: 我在它自己的文件夹中编写一个名为“ namespace @ moduleName ”的“模块”。 我将这个文件夹添加到另一个命名modules 。 当我的应用程序启动时,我的ModuleLoader (基本上通过import {} from 'namespace@moduleName提供的模块可以请求一个服务器API(使用Node)。 在这个API旁边,启动一个脚本。 使用FS ,我正在阅读modules文件夹的内容,以响应一些关于模块的数据(哪些模块被安装,版本是什么)。 回到ModuleLoader,我读取这些信息并configurationSystemJS来添加这些模块(使用map和package )。 ModuleLoader的工作已经结束。 我可以用System.import('core/app').then(null, console.error.bind(console));启动我的应用程序System.import('core/app').then(null, console.error.bind(console)); 我的应用程序启动。 这很简单吧? core/app是指public/core/components/app.component.ts这是我的引导组件Angular 2。 有什么问题? 一切工作正常之前,我更新我的代码。 我遇到了Angular 2,所以我的app.component.ts看起来像这样: import { Component, View } from "angular2/core"; import { RouteConfig, ROUTER_DIRECTIVES, Router } from "angular2/router"; import { Devtools […]

在gulp和nodejs中使用Typescript时需要和导出的未定义引用

我曾经写我的Web应用程序在纯JavaScript,直到我去了解Typescript。 它是一个JavaScript的超集,我没有任何问题,如果我编写和编译它,并使用我的WAMP服务器执行它。 但是我听说了angular2(我知道angular1),我开始学习它使用https://www.lynda.com/AngularJS-tutorials/Learn-AngularJS-2-Basics/428058-2.html课程。 他使用nodejs , gulp , gulp -webserver 。 我做了精确的设置,但最后我得到了 Uncaught ReferenceError:导出未定义@ animal.ts:1。 未捕获的ReferenceError:require未定义@ cat.ts:1 然后,我切换到第一次学习如何设置吞咽环境从https://www.youtube.com/watch?v=7xOubdqyqaY 这里是我的项目目录结构: typescript/ |–app/ —-index.html, load animal.js, cat.js from js/ —-|–js, contains all compiles js files( animal.js, cat.js ) ——-|–lib, contains all library files |–node_modules/ |–typescript/, contains my written typescript files —|–animal.ts —|–cat.ts |–typing/s, contains typescript definition files |–gulp.config.js […]

打字稿 – 打字稿 – 打字| 找不到模块TS2307

我不断收到这些错误: ../src/public/AngularApp/cmsApp/boot.component.ts(4,27): error TS2307: Cannot find module '@angular/core'. ../src/public/AngularApp/main.ts(1,30): error TS2307: Cannot find module '@angular/platform-browser-dynamic'. ../src/server.ts(1,1): error TS6053: File '/LocalProjects/cmsApp/typings/index.d.ts' not found. ../src/server.ts(2,26): error TS2307: Cannot find module 'express'. ../src/server.ts(3,29): error TS2307: Cannot find module 'body-parser'. ../src/server.ts(4,31): error TS2307: Cannot find module 'errorhandler'. ../src/server.ts(5,33): error TS2307: Cannot find module 'method-override'. ../src/server/routes/index.ts(1,26): error TS2307: Cannot find […]

Ionic2 Typescript Device Build Error'uglifyjs failed:SyntaxError:意外的标记操作符«=»,预期的punc«,»`

我正在尝试在Ionic应用程序中创build一个360video播放器。 我的代码如下。 HTML: <ion-content> <video id="videojs-panorama-player" class="video-js vjs-default-skin" src="" crossorigin="anonymous" controls ref="player"> <source src="/assets/beach.mp4" type='video/mp4'> </video> </ion-content> 打字稿: import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import videojs from 'video.js'; import panorama from 'videojs-panorama'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { private player: any; constructor(public navCtrl: NavController, […]