From 0833fd0aed798117333e7b0802b74439418a0581 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 9 Aug 2023 11:03:13 -0700 Subject: [PATCH] Implement this type in method parameter --- .../stc_ts_file_analyzer/src/analyzer/expr/mod.rs | 8 +++++++- .../tests/pass-only/types/keyof/2.ts | 13 +++++++++++++ .../keyof/keyofAndIndexedAccess.error-diff.json | 6 +----- .../keyof/keyofAndIndexedAccess.stats.rust-debug | 2 +- .../stc_ts_type_checker/tests/tsc-stats.rust-debug | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/2.ts 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 a3ab044822..84c11c35de 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs @@ -1550,7 +1550,6 @@ impl Analyzer<'_, '_> { }, _ => {} } - return Err(ErrorKind::Unimplemented { span, msg: format!("access_property_inner: global_this: {:?}", prop), @@ -3053,6 +3052,13 @@ impl Analyzer<'_, '_> { // TODO return Ok(Type::any(span, Default::default())); } + Some(ScopeKind::Method { is_static: false }) => { + if let Some(Some(parent)) = scope.map(|s| s.parent()) { + if let Some(this) = parent.this().map(|v| v.into_owned()).or(parent.get_super_class(false)) { + return self.access_property(span, &this, prop, type_mode, id_ctx, opts); + } + } + } None => { // Global this return Ok(Type::any(span, Default::default())); diff --git a/crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/2.ts b/crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/2.ts new file mode 100644 index 0000000000..1e89d4ff89 --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/2.ts @@ -0,0 +1,13 @@ +// @strictNullChecks: true +// @declaration: true + + +class A { + props: T & { foo: string }; +} + +class B extends A<{ x: number}> { + f(p: this["props"]) { + p.x; + } +} diff --git a/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.error-diff.json index ff6a3adda9..724ce11a8a 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.error-diff.json @@ -4,8 +4,7 @@ "extra_errors": { "TS2345": 8, "TS2339": 2, - "TS2322": 12, - "TS0": 1 + "TS2322": 12 }, "extra_error_lines": { "TS2345": [ @@ -35,9 +34,6 @@ 640, 645, 658 - ], - "TS0": [ - 523 ] } } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.stats.rust-debug index c1d16af4c5..4f0736a120 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/keyof/keyofAndIndexedAccess.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 5, - extra_error: 23, + extra_error: 22, 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 9956d0d163..7501a54aa7 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: 767, + extra_error: 766, panic: 74, } \ No newline at end of file