Skip to content

Commit 839f6b3

Browse files
committed
Add documentation
1 parent 9f7328f commit 839f6b3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Click the type names for complete docs.
122122
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) if you only need one level deep.
123123
- [`PartialOnUndefinedDeep`](source/partial-on-undefined-deep.d.ts) - Create a deep version of another type where all keys accepting `undefined` type are set to optional.
124124
- [`UndefinedOnPartialDeep`](source/undefined-on-partial-deep.d.ts) - Create a deep version of another type where all optional keys are set to also accept `undefined`.
125+
- [`UnwrapPartial`](source/unwrap-partial.d.ts) - Revert the `Partial` modifier on an object type.
125126
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of an `object`/`Map`/`Set`/`Array` type. Use [`Readonly<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) if you only need one level deep.
126127
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
127128
- [`Tagged`](source/tagged.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf). (This replaces the previous [`Opaque`](source/tagged.d.ts) type, which is now deprecated.)
@@ -474,6 +475,8 @@ There are many advanced types most users don't know about.
474475
// NodeConfig interface.
475476
new NodeAppBuilder().config({appName: 'ToDoApp'});
476477
```
478+
479+
`Partial<T>` can be reverted with [`UnwrapPartial`](source/unwrap-partial.d.ts).
477480
</details>
478481

479482
- [`Required<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) - Make all properties in `T` required.

source/unwrap-partial.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
Revert the `Partial` modifier on an object type.
3+
4+
Use case: Infer the underlying type `T` when only `Partial<T>` is available or the original type may not be directly accessible.
5+
6+
@example
7+
```
8+
import type {UnwrapPartial} from 'type-fest';
9+
10+
type Config = Partial<{
11+
port: number;
12+
host: string;
13+
secure?: boolean;
14+
}>;
15+
16+
type InitializedConfig = UnwrapPartial<Config>;
17+
//=> { port: number; host: string; secure?: boolean }
18+
```
19+
20+
If the provided type isn’t of `Partial<T>`, `UnwrapPartial` has no effect on the original type.
21+
22+
@category Object
23+
*/
124
export type UnwrapPartial<PartialObjectType> =
225
PartialObjectType extends Partial<infer ObjectType>
326
? (

0 commit comments

Comments
 (0)