types: improve isDef typing (#7124)

* types: improve isDef typing

* chore: update
This commit is contained in:
neverland 2020-09-07 20:16:54 +08:00 committed by GitHub
parent afe4248799
commit c7303786ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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)}`;

View File

@ -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<T>(val: T): val is NonNullable<T> {
return val !== undefined && val !== null;
}