Categories
TypeScript Answers

How to make a single property optional in TypeScript?

Spread the love

Sometimes, we want to make a single property optional in TypeScript.

In this article, we’ll look at how to make a single property optional in TypeScript.

How to make a single property optional in TypeScript?

To make a single property optional in TypeScript, we can use the Optional type.

For instance, we write

type MakePersonInput = Optional<Person, "nickname">;

to create the MakePersonInput type that makes the nickname property in the Person interface optional.

Conclusion

To make a single property optional in TypeScript, we can use the Optional type.

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 *