From 4d64d1c779e9365b2fddd345d96688726f6e40b2 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Sun, 20 Aug 2023 00:53:11 +0900 Subject: [PATCH] Fix: panic from parse().unwrap() --- .../src/analyzer/generic/inference.rs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs b/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs index 3aca4dcd45..75f5edbf88 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/generic/inference.rs @@ -624,16 +624,24 @@ impl Analyzer<'_, '_> { } if r.is_num() { - return Type::Lit(LitType { - span, - lit: RTsLit::Number(RNumber { - span, - value: src.parse().unwrap(), - raw: None, - }), - metadata: Default::default(), - tracker: Default::default(), - }); + match src.parse() { + Ok(v) => { + return Type::Lit(LitType { + span, + lit: RTsLit::Number(RNumber { span, value: v, raw: None }), + metadata: Default::default(), + tracker: Default::default(), + }) + } + Err(..) => { + return Type::Keyword(KeywordType { + span, + kind: TsKeywordTypeKind::TsNumberKeyword, + metadata: Default::default(), + tracker: Default::default(), + }) + } + } } if l.is_enum_type() || l.is_enum_variant() {