Tag: 打字稿

打字稿导出对象错误声明或预期的语句

有人可以解释为什么这个工作在input对象时打字稿: export const config={ port:4000 }; 这也适用: const config = { port:4000 }; export { config }; 但是这给了一个错误 const config={ port:4000 }; export config; 错误:预期声明或声明。

摩卡忽略了一些testing,尽pipe它们应该运行

我正在重构我的express-decorator NPM包的克隆。 这包括重构先前使用AVA进行的unit testing 。 我决定使用Mocha和Chai来重写它们,因为我喜欢他们定义testing的方式。 那么,我的问题是什么? 看看这个代码(我把它分解来说明问题): test('express', (t) => { @web.basePath('/test') class Test { @web.get('/foo/:id') foo(request, response) { /* The test in question. */ t.is(parseInt(request.params.id), 5); response.send(); } } let app = express(); let controller = new Test(); web.register(app, controller); t.plan(1); return supertest(app) .get('/test/foo/5') .expect(200); }); 此代码工作 。 这里(基本上)是相同的代码,现在使用Mocha和Chai和多个testing : describe('The test express […]

Angular 4 CanActivate guard不会加载与服务一起使用的组件; 简单的Observable.of(true)作品

我试图在Angular中使用CanActivate警卫,当我从它调用服务时,它不工作,并return true甚至return Observable.of(true); 但它工作和加载组件,当我不打电话任何服务,只写Observable.of(true); 在canActivate 以下是该代码的最新工作: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { //return Observable.of(true); return this._userService.verify().subscribe((result: Array<Object>) => { let user : UserDetail = new UserDetail(); Object.keys(user).forEach(key=>{ let listValue = result.filter(m=>m["m_type"]==key); if(listValue.length>0){ user[key] = result.filter(m=>m["m_type"]==key)[0]["m_value"]; } }); this.userDetails = user; return Observable.of(true); //return true; }, (error: any) => { // error when verify so redirect […]

Angular找不到模块“net”

当我在简单的Angular CLI应用程序中添加依赖项时 import {Socket} from 'net'; 运行'ng start'时出错 ERROR in C:/IdeaProjects/GethIPC/src/app/app.component.ts (5,20): Cannot find module 'net'

Typescript Interface vs

我试图给我的mongoose文件分配一个文章数组,但似乎Typescript不喜欢,我不知道为什么它显示这个警告/错误,它是不可分配的。 我的mongoose模式和接口(简体): interface Profile { username: string, articles: [Article] } interface Article { index: number, name: string, } // Mongoose model export interface IProfile extends Profile, Document { } const Article = new Schema({ index: { type: Number, required: true }, name: { type: String, required: true }, }, { _id: false }) const Profile […]

用于存储与PHP $ _sessionvariables相同的Angular session值的variables

我想在login后将用户会话值存储在Angular应用程序中。 我有php的背景,在PHP存储会话值使用$ _SESSION,同样的方式如何存储会话值Angular4。

“angular-bootstrap-md \ index.ts不是编译输出的一部分”

我想在我的项目中使用Angular-Bootstrap,所以我找了一个关于如何下载和安装的教程,并让它在我的电脑上运行。 我正在使用Visual Studio代码。 我find了一个关于如何做到这一点的教程,就是这个: https://github.com/mdbootstrap/Angular-Bootstrap-with-Material-Design 我提到了每一个步骤,但是每当我想要“开始”或“build立”,我都会得到这个奇怪的错误。 基本上每当我想编译,我得到这个错误: bootstrap-weather@0.0.0 build C:\Users\Il\Desktop\WebFrameworks\Opdrachten\AngularBootstrapWeather\BootstrapWeather > ng build Date: 2017-11-07T16:19:07.296Z Hash: d517558fb7e8e3484d3d Time: 9269ms chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered] chunk {main} main.bundle.js, main.bundle.js.map (main) 8.17 kB [initial] [rendered] chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 200 kB [initial] [rendered] chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 465 kB [initial] [rendered] […]

从Javascript调用Typescript类时的语法

我已经写了一个打字稿类,将在传统的JavaScript中调用。 我通过以下方式导入: const ConfigurationManager = require('./ConfigurationManager'); 在结束之后,我最终得到: var ConfigurationManager = /** @class */ (function () { function ConfigurationManager 所以它必须被调用: new ConfigurationManager.ConfigurationManager(…) 创build一个新的实例。 有没有一种方法来清理这个JavaScript的一面是less一点冗长?

节点-java打印脚本导入

我需要在我的打字稿项目中使用node-java node_module。 然而, var java = require("java"); 在打字方式中不起作用,而且 import java = module("java"); 不能正常工作。 我知道我们可能需要一个定义文件等,有一个像https://github.com/borisyankov/DefinitelyTyped 说了这么多,我觉得自己做起来太复杂了。 有没有更简单的解决方法? 谢谢。

如何在Typescript中声明NodeJs模块?

我的消费节点代码如下所示: var helloworld = require('helloworld'); helloworld.sayhello(); 使用Typescript善良,我将如何声明导出sayhello()函数的模块?