Sometimes, we want to make all properties within a TypeScript interface optional.
In this article, we’ll look at how to make all properties within a TypeScript interface optional.
How to make all properties within a TypeScript interface optional?
To make all properties within a TypeScript interface optional, we can use the Partial
type.
For instance, we write
interface Asset {
id: string;
internalId: string;
usage: number;
}
interface AssetDraft extends Partial<Asset> {}
to create the AssetDraft
interface that inherits from Partial<Asset>
.
Partial<Asset>
is a type that makes the properties in the Asset
interface optional.
Conclusion
To make all properties within a TypeScript interface optional, we can use the Partial
type.