zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Typescript] Make your optional fields required in TypeScript

typescript in your Make required optional fields
2023-09-14 08:59:14 时间

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);