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 ๊ฐ€ ๊ฐ์ฒด๊ฐ€ null์ด ์•„๋‹Œ ๊ฒƒ์„ ์ฃผ์žฅํ•˜๊ธฐ๋ฅผ ๊ธฐ๋Œ€ํ•˜๋ฏ€๋กœ ์˜ค๋ฅ˜ ์—†์ด ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ™˜๊ฒฝ


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

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๊ธฐ๋Šฅ ์š”์ฒญ์ด ์•„๋‹Œ ๋ฒ„๊ทธ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค.

strictNullChecks๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด ์–ธ์–ด ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

>๋ชจ๋“  ๋Œ“๊ธ€

๊ธฐ๋Šฅ ์š”์ฒญ์ด ์•„๋‹Œ ๋ฒ„๊ทธ๋กœ ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค.

strictNullChecks๊ฐ€ ํ™œ์„ฑํ™”๋˜๋ฉด ์–ธ์–ด ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰