Skip to content

Commit

Permalink
fix(nullable): does not provide an empty string in the render callback
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Nov 2, 2023
1 parent e53bfa0 commit 5aa4243
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils/nullable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// eslint-disable-next-line no-shadow
export function nullable<V, R, F = null>(v: V, render: (v: Exclude<NonNullable<V>, false>) => R, fallback?: F) {
type Value<V> = Exclude<NonNullable<V>, false | ''>;

export function nullable<V, R, F = null>(v: V, render: (v: Value<V>) => R, fallback?: F) {
if (!v) return fallback || null;

if (Array.isArray(v) && !v.length) return fallback || null;

return render(v as Exclude<NonNullable<V>, false>);
return render(v as Value<V>);
}

0 comments on commit 5aa4243

Please sign in to comment.