Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Implement this type in method parameter #1062

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,6 @@ impl Analyzer<'_, '_> {
},
_ => {}
}

return Err(ErrorKind::Unimplemented {
span,
msg: format!("access_property_inner: global_this: {:?}", prop),
Expand Down Expand Up @@ -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()));
Expand Down
13 changes: 13 additions & 0 deletions crates/stc_ts_file_analyzer/tests/pass-only/types/keyof/2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @strictNullChecks: true
// @declaration: true


class A<T> {
props: T & { foo: string };
}

class B extends A<{ x: number}> {
f(p: this["props"]) {
p.x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"extra_errors": {
"TS2345": 8,
"TS2339": 2,
"TS2322": 12,
"TS0": 1
"TS2322": 12
},
"extra_error_lines": {
"TS2345": [
Expand Down Expand Up @@ -35,9 +34,6 @@
640,
645,
658
],
"TS0": [
523
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 5,
extra_error: 23,
extra_error: 22,
panic: 0,
}
2 changes: 1 addition & 1 deletion crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 3502,
matched_error: 6533,
extra_error: 767,
extra_error: 766,
panic: 74,
}
Loading