From 31ce0f5ef8db6b9ee77cc205b94f7fb376a0a3c4 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Wed, 9 Aug 2023 07:26:43 -0700 Subject: [PATCH] Improve conditional expr --- .../src/analyzer/types/keyof.rs | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs index a464247897..c8d610e165 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/keyof.rs @@ -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(), + }) + }, + ); } } _ => {}