-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Make tuple and custom array declared as interface compatible #413
base: main
Are you sure you want to change the base?
Changes from 1 commit
370071b
ce4cf98
fc48981
71cefdd
0399886
96f4567
f27ad7e
43f4aec
3194496
20f4513
bd11c05
259c374
5928792
2e880cb
135e2b3
e40402d
bba28d3
939a9c0
7e87f8e
78011c1
b794a61
9d463e3
4976748
3d3fcca
e85466f
e4a786b
fb8d765
0a08ed7
bdf5da0
5759dc2
0da1d65
594c1e1
4a839ca
6ba341b
3df5f8b
b8551db
3ea7e93
5f8c1df
97256d8
66ecbd5
ed10347
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,10 @@ use stc_ts_generics::ExpandGenericOpts; | |
use stc_ts_type_ops::{tuple_normalization::TupleNormalizer, Fix}; | ||
use stc_ts_types::{ | ||
name::Name, Accessor, Array, Class, ClassDef, ClassMember, ClassMetadata, ComputedKey, Conditional, ConditionalMetadata, | ||
ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Intersection, | ||
IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, Operator, PropertySignature, | ||
QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, TypeLit, TypeLitMetadata, | ||
TypeParam, TypeParamInstantiation, Union, | ||
ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Interface, | ||
InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, | ||
Operator, PropertySignature, QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, | ||
TypeLit, TypeLitMetadata, TypeParam, TypeParamInstantiation, Union, | ||
}; | ||
use stc_ts_utils::run; | ||
use stc_utils::{ | ||
|
@@ -108,7 +108,6 @@ impl Analyzer<'_, '_> { | |
match ty.normalize() { | ||
Type::Lit(..) | ||
| Type::TypeLit(..) | ||
| Type::Interface(..) | ||
| Type::Class(..) | ||
| Type::ClassDef(..) | ||
| Type::Tuple(..) | ||
|
@@ -117,6 +116,36 @@ impl Analyzer<'_, '_> { | |
| Type::EnumVariant(..) | ||
| Type::Param(_) | ||
| Type::Module(_) => return Ok(ty), | ||
Type::Interface(Interface { | ||
span, | ||
name, | ||
type_params, | ||
extends, | ||
body, | ||
metadata: InterfaceMetadata { common }, | ||
tracker, | ||
}) => { | ||
for extend in extends { | ||
let types = extend.to_owned().type_args.into_iter().flat_map(|cur| cur.params); | ||
let union_type = Type::new_union(*span, types); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It almost solved nest_assignment errors but not RegExpExecArray yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
interface RegExpExecArray extends Array<string> {
index: number;
input: string;
} So you need to check the type arguments of |
||
if let box RExpr::Ident(ident) = &extend.expr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should check for |
||
let RIdent { | ||
node_id, | ||
span, | ||
sym, | ||
optional, | ||
} = ident; | ||
if sym == &js_word!("Array") { | ||
return Ok(Cow::Owned(Type::Array(Array { | ||
span: *span, | ||
elem_type: box union_type, | ||
metadata: Default::default(), | ||
tracker: Default::default(), | ||
}))); | ||
}; | ||
}; | ||
} | ||
} | ||
_ => {} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean we should add more condition here to decrease the range of match arm?
Or It is totally wrong location to implement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the latter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give any tips like where to start first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some match expressions should be added to
stc/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs
Line 1036 in 4033e8b