Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created February 7, 2025 14:42
Show Gist options
  • Save Kcko/69694abda54f0eb607867608c3eaf18e to your computer and use it in GitHub Desktop.
Save Kcko/69694abda54f0eb607867608c3eaf18e to your computer and use it in GitHub Desktop.
/*
Omit je utility typ v TypeScriptu, který umožňuje vytvořit nový typ s vynechanými (omitted) klíči z původního typu. To znamená, že nový typ bude obsahovat všechny vlastnosti z původního typu kromě těch,
které explicitně specifikujete k vynechání
Omit<T, K>
*/
// 1
interface User {
id: number;
name: string;
email: string;
password: string;
}
type PublicUser = Omit<User, 'password'>; // nebo Omit<User, 'password' | 'id'>
const user: PublicUser = {
id: 1,
name: 'Alice',
email: '[email protected]',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment