Created
February 7, 2025 14:41
-
-
Save Kcko/1704d191e29e77015b81cf5c3acb90a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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