Q24: How do `Partial<T>` and `Required<T>` utility types work?
Partial<T>: Constructs a type with all properties ofTset to optional (?).Required<T>: Constructs a type with all properties ofTset to required (removes optional?flags).
Partial and Required Implementation
interface Profile {
name: string;
age?: number;
}
type OptionalProfile = Partial<Profile>; // { name?: string; age?: number; }
type MandatoryProfile = Required<Profile>; // { name: string; age: number; }💡 Partial makes all properties optional; Required makes all properties mandatory.
Key Takeaways
- Partial is ideal for update payload signatures (
patch). - Required guarantees optional fields are populated.