Skip to content

Commit

Permalink
Fix: access property
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrabbit123 committed Aug 13, 2023
1 parent 08a427d commit 15251e2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
11 changes: 11 additions & 0 deletions crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@ impl Analyzer<'_, '_> {
if !self.config.is_builtin {
obj.freeze();
}

let mut obj = self.expand(
span,
obj.into_owned(),
Expand Down Expand Up @@ -2295,6 +2296,13 @@ 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 (
Expand Down Expand Up @@ -2513,6 +2521,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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ function l<T extends {}, P extends keyof T>(s: string, tp: T[P]): void {
}
function m<T extends { a: number }, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
}
function f<T extends object, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
"line": 8,
"col": 5,
"code": 2322
},
{
"file": "tests/tsc/types/nonPrimitive/1.ts",
"line": 11,
"col": 5,
"code": 2322
}
]
1 change: 1 addition & 0 deletions crates/stc_ts_type_checker/tests/conformance.pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2427,6 +2427,7 @@ types/nonPrimitive/nonPrimitiveAndEmptyObject.ts
types/nonPrimitive/nonPrimitiveAndTypeVariables.ts
types/nonPrimitive/nonPrimitiveAsProperty.ts
types/nonPrimitive/nonPrimitiveAssignError.ts
types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts
types/nonPrimitive/nonPrimitiveInFunction.ts
types/nonPrimitive/nonPrimitiveInGeneric.ts
types/nonPrimitive/nonPrimitiveIndexingWithForIn.ts
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 1,
matched_error: 9,
extra_error: 4,
required_error: 0,
matched_error: 10,
extra_error: 0,
panic: 0,
}
6 changes: 3 additions & 3 deletions 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,
required_error: 3501,
matched_error: 6534,
extra_error: 765,
panic: 73,
}

0 comments on commit 15251e2

Please sign in to comment.