diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs index 63bfd0336a..dd37d5205c 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs @@ -297,6 +297,12 @@ impl Analyzer<'_, '_> { .context("tried to get keys of Array (builtin)"); } + Type::This(this) => { + if let Some(ty) = self.scope.this().map(Cow::into_owned) { + return self.keyof(this.span, &ty); + } + } + Type::Interface(..) | Type::Enum(..) => { let ty = self .convert_type_to_type_lit(span, ty.freezed(), Default::default())? diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 244a0ef204..90dba21dcf 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -578,12 +578,14 @@ impl Analyzer<'_, '_> { return Ok(ty); } - let ty = self - .normalize(span, Cow::Owned(prop_ty), opts) - .context("tried to normalize the type of property")? - .into_owned(); - - return Ok(Cow::Owned(ty)); + let prev_this = self.scope.this.take(); + self.scope.this = Some(*obj_ty); + let result = { + self.normalize(span, Cow::Owned(prop_ty), opts) + .context("tried to normalize the type of property") + }; + self.scope.this = prev_this; + return result; } // TODO(kdy1): diff --git a/crates/stc_ts_file_analyzer/tests/pass-only/conformance/types/conditional/conditionalTypes1/4.ts b/crates/stc_ts_file_analyzer/tests/pass-only/conformance/types/conditional/conditionalTypes1/4.ts new file mode 100644 index 0000000000..2d008c3e54 --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/pass-only/conformance/types/conditional/conditionalTypes1/4.ts @@ -0,0 +1,16 @@ +// @strict: true +// @declaration: true + +type OldDiff = ( + & { [P in T]: P; } + & { [P in U]: never; } + & { [x: string]: never; } +)[T]; +interface A { + a: 'a'; +} +interface B1 extends A { + b: 'b'; + c: OldDiff; +} +type c1 = B1['c']; // 'c' | 'b' \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.error-diff.json index 539bf5b803..b9748d69af 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.error-diff.json @@ -30,15 +30,11 @@ ] }, "extra_errors": { - "TS2322": 1, - "TS2344": 1 + "TS2322": 1 }, "extra_error_lines": { "TS2322": [ 21 - ], - "TS2344": [ - 317 ] } } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.stats.rust-debug index d84650c75c..5821a9121b 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/conditional/conditionalTypes1.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 11, matched_error: 9, - extra_error: 2, + extra_error: 1, 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 b72223af99..c1f1543a3a 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, - extra_error: 769, + extra_error: 768, panic: 74, } \ No newline at end of file