[ ] 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์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์์:
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
๊ฐ ๊ฐ์ฒด๊ฐ null์ด ์๋ ๊ฒ์ ์ฃผ์ฅํ๊ธฐ๋ฅผ ๊ธฐ๋ํ๋ฏ๋ก ์ค๋ฅ ์์ด ์์ ํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Angular version: 5.2.2
- Node version: 8.9.1
- Platform: MacOS
- Typescript 2.6.2
๊ธฐ๋ฅ ์์ฒญ์ด ์๋ ๋ฒ๊ทธ๋ก ๊ฐ์ฃผํฉ๋๋ค.
strictNullChecks๊ฐ ํ์ฑํ๋๋ฉด ์ธ์ด ์๋น์ค๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ธฐ๋ฅ ์์ฒญ์ด ์๋ ๋ฒ๊ทธ๋ก ๊ฐ์ฃผํฉ๋๋ค.
strictNullChecks๊ฐ ํ์ฑํ๋๋ฉด ์ธ์ด ์๋น์ค๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.