From c7303786ae223ece2c37476282026c5ae3fc6dae Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 7 Sep 2020 20:16:54 +0800 Subject: [PATCH] types: improve isDef typing (#7124) * types: improve isDef typing * chore: update --- src/coupon-cell/index.tsx | 3 ++- src/utils/index.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coupon-cell/index.tsx b/src/coupon-cell/index.tsx index 87a9c1aa1..86e3b3d59 100644 --- a/src/coupon-cell/index.tsx +++ b/src/coupon-cell/index.tsx @@ -27,12 +27,13 @@ function formatValue(props: CouponCellProps) { if (coupon) { let value = 0; + if (isDef(coupon.value)) { ({ value } = coupon); } if (isDef(coupon.denominations)) { - value = coupon.denominations!; + value = coupon.denominations; } return `-${currency} ${(value / 100).toFixed(2)}`; diff --git a/src/utils/index.ts b/src/utils/index.ts index 83f5ff38b..6386cc111 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -9,7 +9,7 @@ export const isServer: boolean = Vue.prototype.$isServer; // eslint-disable-next-line @typescript-eslint/no-empty-function export function noop() {} -export function isDef(val: unknown): boolean { +export function isDef(val: T): val is NonNullable { return val !== undefined && val !== null; }