I have an interface like this
interface Person {
name?:string;
age? :number;
gender?:string
}
I would like to use that exact same interface type somewhere else. But, I want to modify it telling that all members will never be null. So, it will be like this
name:string;
age :number;
gender:string
Is there a way to modify an interface without rewriting an entire interface? Thanks in advance
CodePudding user response:
Simply use the Required<Type> utility type
Constructs a type consisting of all properties of
Type
set to required. The opposite ofPartial
.
type RequiredPerson = Required<Person>;
Note: Requires at least TypeScript v2.8