Angular: @angular/language-service:支持 strictNullChecks 和 ngIf

创建于 2018-02-01  ·  1评论  ·  资料来源: angular/angular

我提交一个...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

当前行为

启用 Typescript 编译器选项strictNullChecks时,@angular/language-service 会引发错误。

例子:

image

interface Foo {
  bar: string;
}

@Component({
  selector: 'app-foo',
  templateUrl: './foo.component.html'
})
export class FooComponent {
  foo?: Foo;
}

示例 1:

<app-foo *ngIf="foo" [bar]="foo.bar"></app-foo>

示例 2:

<div *ngIf="foo">{{ foo.bar }}</div>
Error: ng: The expression might be null

预期行为

我希望*ngIf断言对象不为空,因此我可以安全地使用它而不会出现任何错误。

环境


Angular version: 5.2.2
- Node version: 8.9.1
- Platform:  MacOS
- Typescript 2.6.2
language-service feature

最有用的评论

我认为这是一个错误,而不是功能请求。

启用 strictNullChecks 时语言服务不可用。

>所有评论

我认为这是一个错误,而不是功能请求。

启用 strictNullChecks 时语言服务不可用。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

lacolaco picture lacolaco  ·  183评论

jpsfs picture jpsfs  ·  144评论

michalstepien picture michalstepien  ·  113评论

marvinscharle picture marvinscharle  ·  122评论

alan-agius4 picture alan-agius4  ·  106评论