嗨,我在tsconfig使用WebStorm 2016.2.2时遇到支持"lib"属性的问题.
我试图编辑在IDE的喜好打字稿版本(Preferences -> Languages & Frameworks -> TypeScript),并指向一个全球安装的打字稿2.0版本,但我仍然得到错误高亮显示之类的东西Object.assign和Promise<any>.
我多次重启IDE,似乎没有任何改变,关于如何修复或调试这个的任何想法?
//tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"strictNullChecks": false,
"baseUrl": "./src",
"paths": {
"core": ["app/core"],
"reactive": ["app/reactive"],
"models": ["app/models"],
"services": ["app/services"]
},
"lib": [
"dom",
"es6"
],
"types": [
"hammerjs",
"jasmine",
"node",
"protractor",
"selenium-webdriver",
"source-map",
"uglify-js",
"webpack"
]
},
"exclude": [
"node_modules",
"dist"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"compileOnSave": false, …Run Code Online (Sandbox Code Playgroud) 每次我"重新格式化代码"时,WebStorm都会在任何空的花括号之间放置一个新行.例如,如果我有这个代码:
export class Example {}
我重新格式化代码(Command + Option + L在mac上),我最终得到了这个:
export class Example {
}
如何阻止编辑器插入新行?WebStorm版本是2016.2
当使用HostListener单击事件并尝试停止该事件的传播时,实际元素上的单击处理程序仍然会触发。
这是相关代码和 stackblitz 的示例。
// Directive
@Directive({
selector: '[appDirective]'
})
export class AppDirective {
@HostListener('click', ['$event']) onClick($event: Event) {
$event.preventDefault();
$event.stopPropagation();
alert('i tried to prevent this...');
}
}
// HTML
<button (click)="doSomething()" appDirective>Click Me</button>
// Click handler
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 6';
doSomething() {
alert('I was not prevented.');
}
}
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?
我开始为我的Angular应用程序进行单元测试,我对如何实际构建tests文件夹有一些疑问.我基本上使用了yeoman角度生成器,所以它配备了Jasmine和Karma预配置.
这是我正在尝试测试的场景......
我有一个"PageHeaderDirective",它显示用户的姓名和电子邮件(如欢迎信息)以及注销链接.页眉指令的代码是无关紧要的,但我需要从后端点击"/ user"端点以获取用户的详细信息.以下是UserService的代码,它被注入到PageHeaderDirective中:
/**
* @ngdoc function
* @name Common.service.UserService
* @description
* Service to retrieve a {@link User} from the backend.
*/
(function () {
'use strict';
angular.module('Common').service('UserService', UserService);
UserService.$inject = ['User', 'Restangular'];
/**
* User service function.
* @param User The {@link User} provider.
* @param Restangular The restangular provider.
*/
function UserService(User, Restangular) {
var userPromise;
return {
getUser: getUser
};
/**
* Retrieves a {@link User} instance from the /user endpoint.
* @returns A promise …Run Code Online (Sandbox Code Playgroud) 我在使用Protractor在我的项目中运行时遇到了问题.我的tsconfig.json文件有问题:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"baseUrl": "./src",
"paths": {
"components": ["app/components"],
"core": ["app/core"],
"data": ["app/data"],
"pages": ["app/pages"],
"schemas": ["app/schemas"],
"utility": ["app/utility"]
}
},
"exclude": [
"node_modules"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": { "rewriteTsconfig": false }
}
Run Code Online (Sandbox Code Playgroud)
它特别失败了"baseUrl"和"paths"选项.如果我把它拿出去,那就完美了.有任何想法吗?
编辑:我目前正在使用Protractor 3.2.2,我们更新到4.0只是为了得到这个堆栈跟踪:
TSError: ? Unable to compile TypeScript
Unknown compiler option 'baseUrl'. (5023)
Unknown compiler option 'paths'. (5023)
at Object.register (/Users/Dan/git/LifeSiteAngular2/node_modules/ts-node/src/index.ts:185:11)
at Object.<anonymous> (/Users/Dan/git/LifeSiteAngular2/node_modules/ts-node/register.js:1:15) …Run Code Online (Sandbox Code Playgroud) typescript ×3
angular ×2
webstorm ×2
angularjs ×1
javascript ×1
mocking ×1
protractor ×1
unit-testing ×1
webpack ×1