Advanced TypeScript patterns including generics, conditional types, mapped types, template literals, and type guards