Files
supabase/apps/studio/lib/isNonNullable.ts
Drake Costa ca4b3bc624 Refactor Storage Create/Edit/Empty/Delete Modals to use Shadcn components (#37517)
* Refactor `StorageMenu` modals to replace deprecated patterns

* add test for `DeleteBucketModal` and update test setup

Note: Because this component uses `useParams`, it's necessary to have the dynamic route segment passed to `next-router-mock`'s `createDynamicRouteParser`. In order not to have to manually list all of these as the application grows, I added a glob utility that uses the `pages/` directory  to automatically generate an array of dynamic route paths in this case.

* add test for `EmptyBucketModal`

* add test for `EditBucketModal` and add `isNonNullable` utility function

* add test for `CreateBucketModal`

* implement requested changes

* implement visual fixes
2025-08-14 21:23:08 +02:00

23 lines
558 B
TypeScript

export type Maybe<T> = T | null | undefined
/**
* Used to test whether a `Maybe` typed value is `null` or `undefined`.
*
* When called, the given value's type is narrowed to `NonNullable<T>`.
*
* ### Example Usage:
*
* ```ts
* const fn = (str: Maybe<string>) => {
* if (!isNonNullable(str)) {
* // typeof str = null | undefined
* // ...
* }
* // typeof str = string
* // ...
* }
* ```
*/
export const isNonNullable = <T extends Maybe<unknown>>(val?: T): val is NonNullable<T> =>
typeof val !== `undefined` && val !== null