Categories
TypeScript Answers

How to make TypeScript interface properties optional?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *