TypeScript 中的代码检查
在 TypeScript 中,ReSharper 2026.3 提供两种代码检查:141 项 检测错误的检查 ,例如语法错误、未解析的符号、编译器错误等(这些检查无法配置或禁用),以及 55 项 专有代码检查 ,您可以 禁用 或更改其 严重性级别。
These code inspections help you detect code issues at design time in all open files, and additionally they allow you to find code issues in specific scope.
可配置的 TypeScript 检查列在下方,并按其 类别 分组。
常见实践和代码改进(4 项检查)
此类别分组的检查主要查找中等严重性的问题,这些问题主要影响代码的可读性。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
抽象类的构造函数可以设为受保护
AbstractClassConstructorCanBeMadeProtected
resharper_abstract_class_constructor_can_be_made_protected_highlighting | 提示 |
引入变量将允许应用类型守卫
IntroduceVariableToApplyGuard
resharper_introduce_variable_to_apply_guard_highlighting | 提示 |
私有类字段可以设为只读
PrivateVariableCanBeMadeReadonly
resharper_private_variable_can_be_made_readonly_highlighting | 提示 |
字符串字面量的使用允许创建专用重载
CreateSpecializedOverload
resharper_create_specialized_overload_highlighting | 提示 |
语法问题(4 项检查)
此类别中的检查报告字符串字面量和文档注释中的 语法问题。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
注释中的语法错误
GrammarMistakeInComment
resharper_grammar_mistake_in_comment_highlighting | 建议 |
标记属性值中的语法错误
GrammarMistakeInMarkupAttribute
resharper_grammar_mistake_in_markup_attribute_highlighting | 建议 |
标记文本中的语法错误
GrammarMistakeInMarkupText
resharper_grammar_mistake_in_markup_text_highlighting | 建议 |
字符串字面量中的语法错误
GrammarMistakeInStringLiteral
resharper_grammar_mistake_in_string_literal_highlighting | 已禁用 |
语言使用机会(9 项检查)
此类别包括代码检查,主要具有 建议严重性级别,当可以使用更高级的语言结构时会通知您。 这些检查检测过时语言版本的语法,并建议使用更现代语言版本的功能。 对于大多数支持的语言,语言版本 可以自动检测或手动设置。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
AMD 模块可以转换为外部模块
AmdExternalModule
resharper_amd_external_module_highlighting | 建议 |
类模拟可以转换为类
Class
resharper_class_highlighting | 建议 |
CommonJs 模块可以转换为外部模块
CommonJsExternalModule
resharper_common_js_external_module_highlighting | 建议 |
函数表达式可以转换为 lambda 表达式
Lambda
resharper_lambda_highlighting | 建议 |
立即调用的函数表达式可以转换为内部模块
InternalModule
resharper_internal_module_highlighting | 建议 |
父类的调用可以转换为 super 调用
SuperCall
resharper_super_call_highlighting | 建议 |
由函数分配的成员可以转换为函数成员
MethodSafeThis
resharper_method_safe_this_highlighting | 建议 |
可能的重载可以通过函数体推断
OverloadSignatureInferring
resharper_overload_signature_inferring_highlighting | 提示 |
使用 'as' 运算符代替类型断言
UseAsInsteadOfTypeCast
resharper_use_as_instead_of_type_cast_highlighting | 提示 |
潜在的代码质量问题(15 项检查)
此类别包括检测关键问题(代码异味)的检查,主要具有 错误 或 警告 级别。 此类别还包括 确保本地化支持的检查。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
无法解析,可能符号位于不可访问的模块中
TsResolvedFromInaccessibleModule
resharper_ts_resolved_from_inaccessible_module_highlighting | 错误 |
以与 require() 参数相同的方式检查 'amd-dependency'
AmdDependencyPathProblem
resharper_amd_dependency_path_problem_highlighting | 已禁用 |
重复的标识符
DuplicateIdentifierError
resharper_duplicate_identifier_error_highlighting | 错误 |
类型注释函数的返回值为空
EmptyReturnValueForTypeAnnotatedFunction
resharper_empty_return_value_for_type_annotated_function_highlighting | 警告 |
导出的实体使用了私有实体
DeclarationVisibilityError
resharper_declaration_visibility_error_highlighting | 错误 |
当设置 NoImplicitAny 时的 '隐式 any' 检查
ImplicitAnyError
resharper_implicit_any_error_highlighting | 错误 |
更具体的签名跟随不太具体的签名
MoreSpecificSignatureAfterLessSpecific
resharper_more_specific_signature_after_less_specific_highlighting | 警告 |
重载比主签名更不具体
LessSpecificOverloadThanMainSignature
resharper_less_specific_overload_than_main_signature_highlighting | 警告 |
在构造函数中分配的参数属性值不会分配给类属性
AssignedValueWontBeAssignedToCorrespondingField
resharper_assigned_value_wont_be_assigned_to_corresponding_field_highlighting | 警告 |
可疑的 'instanceof' 检查
SuspiciousInstanceofCheck
resharper_suspicious_instanceof_check_highlighting | 警告 |
在类成员内的本地函数上下文中使用可疑的 'this'
SuspiciousThisUsage
resharper_suspicious_this_usage_highlighting | 警告 |
可疑的 'typeof' 检查
SuspiciousTypeofCheck
resharper_suspicious_typeof_check_highlighting | 警告 |
类型参数隐藏了外部作用域中声明的类型参数
TypeParameterHidesTypeParamFromOuterScope
resharper_type_parameter_hides_type_param_from_outer_scope_highlighting | 警告 |
在静态初始化器中使用可能未分配的属性
UseOfPossiblyUnassignedProperty
resharper_use_of_possibly_unassigned_property_highlighting | 警告 |
使用未声明的变量
TsNotResolved
resharper_ts_not_resolved_highlighting | 错误 |
代码中的冗余(9 项检查)
此类别中的代码检查会查找冗余和无用代码,这些代码会影响代码的可读性和风格,并且可以安全地移除。 某些代码冗余无法自动修复,其快速修复需要在交互模式下完成,需用户输入。 但大多数冗余可以在无需用户交互的情况下修复,使用 范围内修复 或 代码清理。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
布尔值与布尔值的比较等同于值或取反值
RedundantComparisonWithBoolean
resharper_redundant_comparison_with_boolean_highlighting | 警告 |
布尔值的双重否定是多余的
DoubleNegationOfBoolean
resharper_double_negation_of_boolean_highlighting | 警告 |
重复的引用注释是多余的
DuplicateReferenceComment
resharper_duplicate_reference_comment_highlighting | 警告 |
在 extends/implements 中冗余的父类型规范
RedundantParentTypeDeclaration
resharper_redundant_parent_type_declaration_highlighting | 警告 |
多余的限定符
RedundantQualifier
resharper_redundant_qualifier_highlighting | 警告 |
引用注释创建了循环依赖
CyclicReferenceComment
resharper_cyclic_reference_comment_highlighting | 已禁用 |
三元运算符可以用其条件替代
TernaryCanBeReplacedByItsCondition
resharper_ternary_can_be_replaced_by_its_condition_highlighting | 警告 |
类型转换是多余的:表达式始终为提供的类型
RedundantTypeCast
resharper_redundant_type_cast_highlighting | 警告 |
类型转换是多余的:表达式为结构兼容的类型
RedundantTypeCastStructural
resharper_redundant_type_cast_structural_highlighting | 警告 |
符号声明中的冗余(6 项检查)
此类别包括代码检查,主要为 警告严重性级别,用于检测空的和未使用的符号声明。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
参数不是主签名的一部分
ParameterDoesntMakeAnySense
resharper_parameter_doesnt_make_any_sense_highlighting | 警告 |
冗余的无参数空构造函数
RedundantEmptyConstructor
resharper_redundant_empty_constructor_highlighting | 警告 |
同一项以不同名称导入了两次
SameImportsWithDifferentName
resharper_same_imports_with_different_name_highlighting | 警告 |
类型守卫肯定会为变量生成 'never' 类型
TypeGuardProducesNeverType
resharper_type_guard_produces_never_type_highlighting | 警告 |
类型守卫不会以任何方式影响变量的类型
TypeGuardDoesntAffectAnything
resharper_type_guard_doesnt_affect_anything_highlighting | 警告 |
未使用的本地导入
UnusedLocalImport
resharper_unused_local_import_highlighting | 警告 |
语法风格(5 项检查)
此类别中的检查检测 代码语法样式的违规。 与大多数代码检查不同,这些检查是否将相同的代码结构检测为代码问题取决于在 ReSharper 选项 的 页面上配置的相应代码风格规则
Alt+R, O
。 您还可以使用 代码清理修复这些检查检测到的问题。
检查 ID EditorConfig 属性 | 默认严重性 |
|---|
元素具有隐式 'any' 类型
ImplicitAnyTypeWarning
resharper_implicit_any_type_warning_highlighting | 警告 |
在 'require' 中的路径样式不符合规范
WrongRequireRelativePath
resharper_wrong_require_relative_path_highlighting | 提示 |
不符合规范的 'public' 修饰符或其缺失
WrongPublicModifierSpecification
resharper_wrong_public_modifier_specification_highlighting | 提示 |
可以显式指定变量的类型
SpecifyVariableTypeExplicitly
resharper_specify_variable_type_explicitly_highlighting | 提示 |
类型规范是多余的,因为变量类型是根据分配值的类型上下文确定的
RedundantVariableTypeSpecification
resharper_redundant_variable_type_specification_highlighting | 提示 |
2026年 11月 6日