Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit d1ce863

Browse files
committed
IndexedAccessType
1 parent 4a48d97 commit d1ce863

File tree

11 files changed

+35
-27
lines changed

11 files changed

+35
-27
lines changed

crates/stc_ts_file_analyzer/src/analyzer/assign/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Analyzer<'_, '_> {
112112
AccessPropertyOpts {
113113
do_not_validate_type_of_computed_prop: true,
114114
disallow_indexing_array_with_string: true,
115-
disallow_creating_indexed_type_from_ty_els: true,
115+
disallow_creating_indexed_type: true,
116116
disallow_indexing_class_with_computed: true,
117117
use_undefined_for_tuple_index_error: true,
118118
..Default::default()
@@ -132,7 +132,7 @@ impl Analyzer<'_, '_> {
132132
AccessPropertyOpts {
133133
do_not_validate_type_of_computed_prop: true,
134134
disallow_indexing_array_with_string: true,
135-
disallow_creating_indexed_type_from_ty_els: true,
135+
disallow_creating_indexed_type: true,
136136
disallow_indexing_class_with_computed: true,
137137
use_undefined_for_tuple_index_error: true,
138138
..Default::default()

crates/stc_ts_file_analyzer/src/analyzer/assign/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl Analyzer<'_, '_> {
860860
IdCtx::Var,
861861
AccessPropertyOpts {
862862
disallow_indexing_array_with_string: true,
863-
disallow_creating_indexed_type_from_ty_els: true,
863+
disallow_creating_indexed_type: true,
864864
disallow_indexing_class_with_computed: true,
865865
disallow_inexact: true,
866866
use_last_element_for_tuple_on_out_of_bound: true,
@@ -899,7 +899,7 @@ impl Analyzer<'_, '_> {
899899
IdCtx::Var,
900900
AccessPropertyOpts {
901901
disallow_indexing_array_with_string: true,
902-
disallow_creating_indexed_type_from_ty_els: true,
902+
disallow_creating_indexed_type: true,
903903
disallow_indexing_class_with_computed: true,
904904
disallow_inexact: true,
905905
use_last_element_for_tuple_on_out_of_bound: true,

crates/stc_ts_file_analyzer/src/analyzer/class/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Analyzer<'_, '_> {
168168
TypeOfMode::RValue,
169169
IdCtx::Var,
170170
AccessPropertyOpts {
171-
disallow_creating_indexed_type_from_ty_els: true,
171+
disallow_creating_indexed_type: true,
172172
..Default::default()
173173
},
174174
) {
@@ -242,7 +242,7 @@ impl Analyzer<'_, '_> {
242242
TypeOfMode::RValue,
243243
IdCtx::Var,
244244
AccessPropertyOpts {
245-
disallow_creating_indexed_type_from_ty_els: true,
245+
disallow_creating_indexed_type: true,
246246
..Default::default()
247247
},
248248
) {
@@ -693,7 +693,7 @@ impl Analyzer<'_, '_> {
693693
TypeOfMode::RValue,
694694
IdCtx::Var,
695695
AccessPropertyOpts {
696-
disallow_creating_indexed_type_from_ty_els: true,
696+
disallow_creating_indexed_type: true,
697697
..Default::default()
698698
},
699699
) {

crates/stc_ts_file_analyzer/src/analyzer/control_flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl Analyzer<'_, '_> {
12861286
TypeOfMode::RValue,
12871287
IdCtx::Var,
12881288
AccessPropertyOpts {
1289-
disallow_creating_indexed_type_from_ty_els: true,
1289+
disallow_creating_indexed_type: true,
12901290
..Default::default()
12911291
},
12921292
)

crates/stc_ts_file_analyzer/src/analyzer/expr/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl Analyzer<'_, '_> {
513513
IdCtx::Var,
514514
AccessPropertyOpts {
515515
disallow_indexing_array_with_string: true,
516-
disallow_creating_indexed_type_from_ty_els: true,
516+
disallow_creating_indexed_type: true,
517517
..Default::default()
518518
},
519519
);
@@ -541,7 +541,7 @@ impl Analyzer<'_, '_> {
541541
IdCtx::Var,
542542
AccessPropertyOpts {
543543
disallow_indexing_array_with_string: true,
544-
disallow_creating_indexed_type_from_ty_els: true,
544+
disallow_creating_indexed_type: true,
545545
..Default::default()
546546
},
547547
)

crates/stc_ts_file_analyzer/src/analyzer/expr/jsx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Analyzer<'_, '_> {
5555
TypeOfMode::RValue,
5656
IdCtx::Var,
5757
AccessPropertyOpts {
58-
disallow_creating_indexed_type_from_ty_els: true,
58+
disallow_creating_indexed_type: true,
5959
..Default::default()
6060
},
6161
)
@@ -85,7 +85,7 @@ impl Analyzer<'_, '_> {
8585
TypeOfMode::RValue,
8686
IdCtx::Var,
8787
AccessPropertyOpts {
88-
disallow_creating_indexed_type_from_ty_els: true,
88+
disallow_creating_indexed_type: true,
8989
..Default::default()
9090
},
9191
)
@@ -127,7 +127,7 @@ impl Analyzer<'_, '_> {
127127
TypeOfMode::RValue,
128128
IdCtx::Var,
129129
AccessPropertyOpts {
130-
disallow_creating_indexed_type_from_ty_els: true,
130+
disallow_creating_indexed_type: true,
131131
..Default::default()
132132
},
133133
)
@@ -435,7 +435,7 @@ impl Analyzer<'_, '_> {
435435
TypeOfMode::RValue,
436436
IdCtx::Var,
437437
AccessPropertyOpts {
438-
disallow_creating_indexed_type_from_ty_els: true,
438+
disallow_creating_indexed_type: true,
439439
..Default::default()
440440
},
441441
)

crates/stc_ts_file_analyzer/src/analyzer/expr/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ pub(crate) struct AccessPropertyOpts {
655655
///
656656
/// obj11.foo; // Error TS2339
657657
/// ```
658-
pub disallow_creating_indexed_type_from_ty_els: bool,
658+
pub disallow_creating_indexed_type: bool,
659659

660660
pub disallow_indexing_class_with_computed: bool,
661661

@@ -1165,7 +1165,7 @@ impl Analyzer<'_, '_> {
11651165
}
11661166
}
11671167

1168-
if has_index_signature && !opts.disallow_creating_indexed_type_from_ty_els {
1168+
if has_index_signature && !opts.disallow_creating_indexed_type {
11691169
// This check exists to prefer a specific property over generic index signature.
11701170
if prop.is_computed() || matching_elements.is_empty() {
11711171
warn!("Creating a indexed access type from a type literal");
@@ -1278,7 +1278,7 @@ impl Analyzer<'_, '_> {
12781278
id_ctx,
12791279
AccessPropertyOpts {
12801280
disallow_indexing_array_with_string: true,
1281-
disallow_creating_indexed_type_from_ty_els: true,
1281+
disallow_creating_indexed_type: true,
12821282
is_key_computed: true,
12831283
..opts
12841284
},
@@ -2187,6 +2187,15 @@ impl Analyzer<'_, '_> {
21872187
}
21882188
}
21892189

2190+
if opts.disallow_creating_indexed_type {
2191+
return Err(ErrorKind::NoSuchProperty {
2192+
span,
2193+
obj: Some(Box::new(obj.clone())),
2194+
prop: Some(Box::new(prop.clone())),
2195+
}
2196+
.context("type parameter"));
2197+
}
2198+
21902199
let mut prop_ty = match prop {
21912200
Key::Computed(key) => key.ty.clone(),
21922201
Key::Normal { span, sym } => Box::new(Type::Lit(LitType {
@@ -2398,8 +2407,7 @@ impl Analyzer<'_, '_> {
23982407
type_mode,
23992408
id_ctx,
24002409
AccessPropertyOpts {
2401-
disallow_creating_indexed_type_from_ty_els: opts.disallow_creating_indexed_type_from_ty_els
2402-
|| has_better_default,
2410+
disallow_creating_indexed_type: opts.disallow_creating_indexed_type || has_better_default,
24032411
..opts
24042412
},
24052413
)
@@ -2591,7 +2599,7 @@ impl Analyzer<'_, '_> {
25912599
id_ctx,
25922600
AccessPropertyOpts {
25932601
use_undefined_for_tuple_index_error,
2594-
disallow_creating_indexed_type_from_ty_els: true,
2602+
disallow_creating_indexed_type: true,
25952603
is_in_union: true,
25962604
..opts
25972605
},

crates/stc_ts_file_analyzer/src/analyzer/generic/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ impl Analyzer<'_, '_> {
22442244
AccessPropertyOpts {
22452245
do_not_validate_type_of_computed_prop: true,
22462246
disallow_indexing_array_with_string: true,
2247-
disallow_creating_indexed_type_from_ty_els: true,
2247+
disallow_creating_indexed_type: true,
22482248
disallow_indexing_class_with_computed: true,
22492249
use_undefined_for_tuple_index_error: true,
22502250
return_rest_tuple_element_as_is: true,
@@ -2265,7 +2265,7 @@ impl Analyzer<'_, '_> {
22652265
AccessPropertyOpts {
22662266
do_not_validate_type_of_computed_prop: true,
22672267
disallow_indexing_array_with_string: true,
2268-
disallow_creating_indexed_type_from_ty_els: true,
2268+
disallow_creating_indexed_type: true,
22692269
disallow_indexing_class_with_computed: true,
22702270
use_undefined_for_tuple_index_error: true,
22712271
return_rest_tuple_element_as_is: true,

crates/stc_ts_file_analyzer/src/analyzer/scope/vars.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl Analyzer<'_, '_> {
654654
IdCtx::Var,
655655
AccessPropertyOpts {
656656
disallow_indexing_array_with_string: true,
657-
disallow_creating_indexed_type_from_ty_els: true,
657+
disallow_creating_indexed_type: true,
658658
disallow_inexact: true,
659659
..Default::default()
660660
},
@@ -675,7 +675,7 @@ impl Analyzer<'_, '_> {
675675
IdCtx::Var,
676676
AccessPropertyOpts {
677677
disallow_indexing_array_with_string: true,
678-
disallow_creating_indexed_type_from_ty_els: true,
678+
disallow_creating_indexed_type: true,
679679
disallow_inexact: true,
680680
..Default::default()
681681
},
@@ -750,7 +750,7 @@ impl Analyzer<'_, '_> {
750750
IdCtx::Var,
751751
AccessPropertyOpts {
752752
disallow_indexing_array_with_string: true,
753-
disallow_creating_indexed_type_from_ty_els: true,
753+
disallow_creating_indexed_type: true,
754754
disallow_inexact: true,
755755
..Default::default()
756756
},
@@ -771,7 +771,7 @@ impl Analyzer<'_, '_> {
771771
IdCtx::Var,
772772
AccessPropertyOpts {
773773
disallow_indexing_array_with_string: true,
774-
disallow_creating_indexed_type_from_ty_els: true,
774+
disallow_creating_indexed_type: true,
775775
disallow_inexact: true,
776776
..Default::default()
777777
},

crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ impl Analyzer<'_, '_> {
566566
TypeOfMode::RValue,
567567
IdCtx::Type,
568568
AccessPropertyOpts {
569-
disallow_creating_indexed_type_from_ty_els: true,
569+
disallow_creating_indexed_type: true,
570570
disallow_inexact: true,
571571
do_not_use_any_for_object: true,
572572
..Default::default()

0 commit comments

Comments
 (0)