/** * @description Creates a new type by taking type T and overwriting properties that exist in U with U's types. * Properties in U that are not in T are also included. * @template T The base type. * @template U The type whose properties will override T's and be added. */ type Overwrite = Omit & U; // --- Usage Example --- interface BaseSettings { theme: 'light' | 'dark'; fontSize: number; notifications: boolean; language: string; } interface UserSettings { theme: 'dark'; // Overwrites 'theme' from BaseSettings notifications: 'email' | 'sms'; // Overwrites 'notifications' analytics: boolean; // New property, not in BaseSettings } type FinalSettings = Overwrite; /* Expected: { fontSize: number; language: string; theme: 'dark'; // Overwritten notifications: 'email' | 'sms'; // Overwritten analytics: boolean; // Added } */ const settings: FinalSettings = { fontSize: 16, language: 'en-US', theme: 'dark', // Must be 'dark' notifications: 'email', // Must be 'email' or 'sms' analytics: true, }; // This would cause a type error because 'theme' must be 'dark' // const invalidSettings: FinalSettings = { // fontSize: 16, // language: 'en-US', // theme: 'light', // notifications: 'email', // analytics: true, // };