Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrabbit123 committed Aug 13, 2023
1 parent 92191dc commit 08a427d
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 36 deletions.
16 changes: 7 additions & 9 deletions crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,14 @@ impl Analyzer<'_, '_> {
}

if r.is_num() {
return Type::Lit(LitType {
span,
lit: RTsLit::Number(RNumber {
if let Ok(value) = src.parse() {
return Type::Lit(LitType {
span,
value: src.parse().unwrap(),
raw: None,
}),
metadata: Default::default(),
tracker: Default::default(),
});
lit: RTsLit::Number(RNumber { span, value, raw: None }),
metadata: Default::default(),
tracker: Default::default(),
});
}
}

if l.is_enum_type() || l.is_enum_variant() {
Expand Down
7 changes: 5 additions & 2 deletions crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use stc_ts_errors::{debug::force_dump_type_as_string, DebugExt, ErrorKind};
use stc_ts_type_ops::{is_str_lit_or_union, Fix};
use stc_ts_types::{
Class, ClassMember, ClassProperty, Index, KeywordType, KeywordTypeMetadata, LitType, Method, MethodSignature, PropertySignature,
Readonly, Ref, Type, TypeElement, Union,
Readonly, Ref, Type, TypeElement, TypeParam, Union,
};
use stc_utils::{cache::Freeze, ext::TypeVecExt, stack, try_cache};
use swc_atoms::js_word;
Expand Down Expand Up @@ -365,7 +365,10 @@ impl Analyzer<'_, '_> {
return Ok(Type::new_union(span, key_types));
}

Type::Param(..) => {
Type::Param(TypeParam { constraint, .. }) => {
if let Some(box c) = constraint {
return self.keyof(span, c);
}
return Ok(Type::Index(Index {
span,
ty: Box::new(ty.into_owned()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"file": "tests/tsc/types/nonPrimitive/1.ts",
"line": 5,
"col": 5,
"code": 2322
},
{
"file": "tests/tsc/types/nonPrimitive/1.ts",
"line": 8,
"col": 5,
"code": 2322
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required_errors": {},
"required_error_lines": {},
"extra_errors": {
"TS2345": 8,
"TS2345": 10,
"TS2339": 2,
"TS0": 2,
"TS2322": 8
Expand All @@ -11,6 +11,8 @@
"TS2345": [
96,
132,
157,
162,
291,
295,
296,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 5,
extra_error: 20,
extra_error: 22,
panic: 0,
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required_errors": {
"TS2339": 2,
"TS2322": 7,
"TS2322": 6,
"TS7053": 1,
"TS2536": 1
},
Expand All @@ -14,7 +14,6 @@
30,
34,
41,
55,
56,
70,
71
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 11,
matched_error: 12,
required_error: 10,
matched_error: 13,
extra_error: 2,
panic: 0,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"required_errors": {
"TS2322": 13,
"TS2322": 16,
"TS2536": 4,
"TS2542": 4
},
Expand All @@ -9,6 +9,9 @@
14,
19,
33,
43,
44,
64,
75,
81,
91,
Expand All @@ -34,14 +37,13 @@
]
},
"extra_errors": {
"TS2322": 5
"TS2322": 4
},
"extra_error_lines": {
"TS2322": [
39,
58,
59,
63,
68
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 21,
matched_error: 7,
extra_error: 5,
required_error: 24,
matched_error: 4,
extra_error: 4,
panic: 0,
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"required_errors": {
"TS2322": 2
"TS2322": 1
},
"required_error_lines": {
"TS2322": [
25,
28
25
]
},
"extra_errors": {},
"extra_error_lines": {}
"extra_errors": {
"TS2322": 4
},
"extra_error_lines": {
"TS2322": [
4,
4,
4,
4
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 2,
matched_error: 8,
extra_error: 0,
required_error: 1,
matched_error: 9,
extra_error: 4,
panic: 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required_errors": {
"TS2345": 1,
"TS2344": 1,
"TS2322": 5,
"TS2322": 4,
"TS4104": 2
},
"required_error_lines": {
Expand All @@ -16,7 +16,6 @@
155,
185,
194,
206,
360
],
"TS4104": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 9,
matched_error: 11,
required_error: 8,
matched_error: 12,
extra_error: 18,
panic: 0,
}
3 changes: 2 additions & 1 deletion crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Stats {
required_error: 3502,
matched_error: 6533,
extra_error: 764,
extra_error: 769,
panic: 73,
}

0 comments on commit 08a427d

Please sign in to comment.