Skip to content

Commit

Permalink
Improve conditional expr
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrabbit123 committed Aug 9, 2023
1 parent 1cc16a6 commit 31ce0f5
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,45 +381,43 @@ impl Analyzer<'_, '_> {
}
}
Type::EnumVariant(e) => {
if matches!(e.name, None) {
if e.def.has_num || e.def.has_str {
return self.keyof(
span,
&if e.def.has_num && e.def.has_str {
Type::new_intersection(
span,
[
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsStringKeyword,
metadata: Default::default(),
tracker: Default::default(),
}),
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsNumberKeyword,
metadata: Default::default(),
tracker: Default::default(),
}),
],
)
} else if e.def.has_num {
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsNumberKeyword,
metadata: Default::default(),
tracker: Default::default(),
})
} else {
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsStringKeyword,
metadata: Default::default(),
tracker: Default::default(),
})
},
);
}
if matches!(e.name, None) && (e.def.has_num || e.def.has_str) {
return self.keyof(
span,
&if e.def.has_num && e.def.has_str {
Type::new_intersection(
span,
[
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsStringKeyword,
metadata: Default::default(),
tracker: Default::default(),
}),
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsNumberKeyword,
metadata: Default::default(),
tracker: Default::default(),
}),
],
)
} else if e.def.has_num {
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsNumberKeyword,
metadata: Default::default(),
tracker: Default::default(),
})
} else {
Type::Keyword(KeywordType {
span,
kind: TsKeywordTypeKind::TsStringKeyword,
metadata: Default::default(),
tracker: Default::default(),
})
},
);
}
}
_ => {}
Expand Down

0 comments on commit 31ce0f5

Please sign in to comment.