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: not implement keyof this #1059

Merged
merged 7 commits into from
Aug 9, 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
6 changes: 6 additions & 0 deletions crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?
Expand Down
14 changes: 8 additions & 6 deletions crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @strict: true
// @declaration: true

type OldDiff<T extends keyof any, U extends keyof any> = (
& { [P in T]: P; }
& { [P in U]: never; }
& { [x: string]: never; }
)[T];
interface A {
a: 'a';
}
interface B1 extends A {
b: 'b';
c: OldDiff<keyof this, keyof A>;
}
type c1 = B1['c']; // 'c' | 'b'
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
]
},
"extra_errors": {
"TS2322": 1,
"TS2344": 1
"TS2322": 1
},
"extra_error_lines": {
"TS2322": [
21
],
"TS2344": [
317
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 11,
matched_error: 9,
extra_error: 2,
extra_error: 1,
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: 769,
extra_error: 768,
panic: 74,
}
Loading