Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created February 7, 2025 14:41
Show Gist options
  • Save Kcko/1704d191e29e77015b81cf5c3acb90a9 to your computer and use it in GitHub Desktop.
Save Kcko/1704d191e29e77015b81cf5c3acb90a9 to your computer and use it in GitHub Desktop.
/*
NonNullable je utility typ v TypeScriptu, který odstraní null a undefined z daného typu. To znamená, že výsledný typ bude obsahovat všechny hodnoty z původního typu kromě null a undefined
NonNullable<T>
*/
// 1
type UserInput = string | number | null | undefined;
function processUserInput(input: NonNullable<UserInput>) {
console.log(`Processing user input: ${input}`);
}
processUserInput('Hello');
processUserInput(42);
// Below would cause compile-time errors:
processUserInput(null);
processUserInput(undefined);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment