From 73282c23fddb0137413c4e7a2cd8124bdefeafeb Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Sun, 20 Aug 2023 01:09:55 +0900 Subject: [PATCH 1/2] fix: nom primitive constriant of indexed access type at empty object --- crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs | 9 +++++++++ ...nPrimitiveConstraintOfIndexAccessType.error-diff.json | 3 +-- ...PrimitiveConstraintOfIndexAccessType.stats.rust-debug | 4 ++-- crates/stc_ts_type_checker/tests/tsc-stats.rust-debug | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs index 84c11c35de..f42ea465a4 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -2295,6 +2295,12 @@ impl Analyzer<'_, '_> { return Err(ErrorKind::IsTypeUnknown { span }.into()); } + // Type::Keyword(KeywordType { + // kind: TsKeywordTypeKind::TsObjectKeyword, + // .. + // }) if matches!(type_mode, TypeOfMode::LValue) && prop.ty().is_type_param() => { + // return Ok(Type::never(span, Default::default())); + // } Type::Keyword(KeywordType { kind, .. }) if !self.config.is_builtin => { if let Key::Computed(prop) = prop { if let ( @@ -2513,6 +2519,9 @@ impl Analyzer<'_, '_> { } if type_mode == TypeOfMode::LValue { + if prop.ty().is_type_param() && members.is_empty() { + return Ok(Type::never(span, Default::default())); + } return Ok(Type::any(span, Default::default())); } diff --git a/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.error-diff.json index f8c3529e5f..b6be05c17d 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.error-diff.json @@ -1,10 +1,9 @@ { "required_errors": { - "TS2322": 2 + "TS2322": 1 }, "required_error_lines": { "TS2322": [ - 25, 28 ] }, diff --git a/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.stats.rust-debug index 13ac66ffd7..4074730ba8 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.stats.rust-debug @@ -1,6 +1,6 @@ Stats { - required_error: 2, - matched_error: 8, + required_error: 1, + matched_error: 9, extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index 02553a0cb6..57039bc151 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { - required_error: 3502, - matched_error: 6533, + required_error: 3501, + matched_error: 6534, extra_error: 764, panic: 73, } \ No newline at end of file From 86b831f74f73cbc585ea0f0fa49c39cb6a5ccab0 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Sun, 20 Aug 2023 01:10:27 +0900 Subject: [PATCH 2/2] remove comment --- crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs index f42ea465a4..0e81cc3ecc 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -2295,12 +2295,6 @@ impl Analyzer<'_, '_> { return Err(ErrorKind::IsTypeUnknown { span }.into()); } - // Type::Keyword(KeywordType { - // kind: TsKeywordTypeKind::TsObjectKeyword, - // .. - // }) if matches!(type_mode, TypeOfMode::LValue) && prop.ty().is_type_param() => { - // return Ok(Type::never(span, Default::default())); - // } Type::Keyword(KeywordType { kind, .. }) if !self.config.is_builtin => { if let Key::Computed(prop) = prop { if let (