-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathoptional.d.ts
More file actions
31 lines (24 loc) · 763 Bytes
/
optional.d.ts
File metadata and controls
31 lines (24 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
Create a type that represents either the value or `undefined`, while stripping `null` from the type.
Use-cases:
- Enforcing the practice of using `undefined` instead of `null` as the "absence of value" marker.
- Converting APIs that return `null` (DOM, JSON, legacy libraries) to use `undefined` consistently.
@example
```
import type {Optional} from 'type-fest';
// Adds `undefined` to the type
type MaybeNumber = Optional<number>;
//=> number | undefined
// Strips `null` from the type
type NullableString = Optional<string | null>;
//=> string | undefined
type Config = {
name: string;
description: Optional<string>;
//=> string | undefined
};
```
@category Utilities
*/
export type Optional<Value> = Exclude<Value, null> | undefined;
export {};