小编exk*_*730的帖子

在诸如`Object.assign`和`Promise <any>`之类的东西上获得错误突出显示

嗨,我在tsconfig使用WebStorm 2016.2.2时遇到支持"lib"属性的问题.

我试图编辑在IDE的喜好打字稿版本(Preferences -> Languages & Frameworks -> TypeScript),并指向一个全球安装的打字稿2.0版本,但我仍然得到错误高亮显示之类的东西Object.assignPromise<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 typescript

6
推荐指数
1
解决办法
1251
查看次数

WebStorm,空代码块和花括号

每次我"重新格式化代码"时,WebStorm都会在任何空的花括号之间放置一个新行.例如,如果我有这个代码:

export class Example {}

我重新格式化代码(Command + Option + L在mac上),我最终得到了这个:

export class Example { }

如何阻止编辑器插入新行?WebStorm版本是2016.2

webstorm typescript

6
推荐指数
1
解决办法
841
查看次数

停止点击的指令不起作用 Angular 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)

难道我做错了什么?

https://angular-nufbqg.stackblitz.io

angular

6
推荐指数
1
解决办法
3073
查看次数

AngularJS单元测试 - 多个模拟和提供程序

我开始为我的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)

javascript unit-testing mocking angularjs

5
推荐指数
1
解决办法
1186
查看次数

具有TypeScript + Angular 2的量角器配置错误

我在使用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 protractor webpack angular

3
推荐指数
1
解决办法
1140
查看次数