이 진단은 템플릿에서 값을 한 번도 읽지 않는 @let 선언을 감지합니다.
import {Component} from '@angular/core';
@Component({
template: `
@let fullName = user.firstName + ' ' + user.lastName;
<h1>Welcome</h1>
`,
})
class MyComponent {
user = {firstName: 'Ada', lastName: 'Lovelace'};
}
어떤 문제가 있나요?
사용하지 않는 @let은 보통 리팩토링 후 남은 코드이거나 원래 값을 사용하려던 위치를 나타냅니다. Angular는 템플릿을 갱신할 때마다 사용하지 않는 @let의 표현식도 평가합니다. 예를 들어 표현식에 함수 호출이 있으면 그 함수도 계속 실행됩니다.
어떻게 수정해야 하나요?
선언을 사용하거나 제거하세요.
권장
use the declaration
@Component({
template: `
@let fullName = user.firstName + ' ' + user.lastName;
<h1>Welcome, {{ fullName }}</h1>
`,
})
class MyComponent {
user = {firstName: 'Ada', lastName: 'Lovelace'};
}
권장
remove the declaration
@Component({
template: `<h1>Welcome</h1>`,
})
class MyComponent {}
피할 수 없다면 어떻게 하나요?
프로젝트의 tsconfig.json 파일을 편집하여 이 진단을 비활성화할 수 있습니다.
{
"angularCompilerOptions": {
"extendedDiagnostics": {
"checks": {
"unusedLetDeclaration": "suppress"
}
}
}
}
자세한 내용은 확장 진단 설정을 참고하세요.