Sometimes, we want to make TypeScript interface properties optional.
In this article, we’ll look at how to make TypeScript interface properties optional.
How to make TypeScript interface properties optional?
To make TypeScript interface properties optional, we can add a ?
after the property name.
For instance, we write
interface I {
a: string;
b?: any;
c?: AnotherType;
}
to create the I
interface with the b
and c
properties made optional by appending a ?
to each property name.
Conclusion
To make TypeScript interface properties optional, we can add a ?
after the property name.