首页 > 其他 > 详细

[Typescript] Make your optional fields required in TypeScript

时间:2020-02-17 00:42:28      阅读:102      评论:0      收藏:0      [点我收藏+]

In this post, let‘s see how to make all the optional fields to be required with the help of Required.

type User = {
  name: string;
  age?: number;
  gender?: string;
};

const user: Required<User> = {
  name: "John Doe",
  age: 23,
  gender: "male"
};

console.log(user);

 

[Typescript] Make your optional fields required in TypeScript

原文:https://www.cnblogs.com/Answer1215/p/12319296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!