1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use stc_ts_types::{replace::replace_type, Mapped, Type, TypeParam};
use stc_ts_utils::MapWithMut;
pub fn reduce(m: &Mapped) -> Option<Type> {
let mut type_param = m.type_param.clone();
if let Some(constraint) = &mut type_param.constraint {
replace_type(
constraint,
|ty| {
if let Type::Param(TypeParam {
constraint: Some(box arr_ty @ Type::Array(..)),
..
}) = ty
{
return true;
}
false
},
|ty| {
if let Type::Param(TypeParam {
constraint: Some(box arr_ty @ Type::Array(..)),
..
}) = ty
{
let arr_ty = arr_ty.take();
return Some(arr_ty);
}
None
},
)
}
type_param.constraint.map(|v| *v)
}