使用 forwardRef 时 angular2+ tslint 显示 'variable xxx used before declaration'
angular2+ tslint show 'variable xxx used before declaration' when using forwardRef
我正在使用 'forwardRef' 编写自定义表单组件。它有效,但在运行 ng lint 时,显示 'variable FormMultiInputComponent used before declaration'。
那么如何避免错误呢?
export const EXE_COUNTER_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => FormMultiInputComponent),
multi: true
};
@Component({
selector: 'cmss-form-multi-input',
templateUrl: './form-multi-input.component.html',
styleUrls: ['./form-multi-input.component.scss'],
providers: [EXE_COUNTER_VALUE_ACCESSOR]
})
要解决此问题,您可以在 TSLINT json 文件
上设置 "no-use-before-declare": false
来自Docs
This rule is primarily useful when using the var keyword since the
compiler will automatically detect if a block-scoped let and const
variable is used before declaration. Since most modern TypeScript
doesn’t use var, this rule is generally discouraged and is kept around
for legacy purposes. It is slow to compute, is not enabled in the
built-in configuration presets, and should not be used to inform
TSLint design decisions.
我正在使用 'forwardRef' 编写自定义表单组件。它有效,但在运行 ng lint 时,显示 'variable FormMultiInputComponent used before declaration'。 那么如何避免错误呢?
export const EXE_COUNTER_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => FormMultiInputComponent),
multi: true
};
@Component({
selector: 'cmss-form-multi-input',
templateUrl: './form-multi-input.component.html',
styleUrls: ['./form-multi-input.component.scss'],
providers: [EXE_COUNTER_VALUE_ACCESSOR]
})
要解决此问题,您可以在 TSLINT json 文件
上设置"no-use-before-declare": false
来自Docs
This rule is primarily useful when using the var keyword since the compiler will automatically detect if a block-scoped let and const variable is used before declaration. Since most modern TypeScript doesn’t use var, this rule is generally discouraged and is kept around for legacy purposes. It is slow to compute, is not enabled in the built-in configuration presets, and should not be used to inform TSLint design decisions.