Created
December 24, 2020 19:40
-
-
Save jarodsim/64affec360cb7175e50b7d2c866d6df8 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
/** Type Allias e Union */ | |
function logDetails(uid: number | string, item: string) { | |
console.log(`A product with ${uid} has a title as ${item}`) | |
} | |
// uid: number | string => union | |
logDetails(123, 'sapato') | |
logDetails('123', 'sapato') | |
function logInfo(uid: number | string, user: string) { | |
console.log(`A user with ${uid} has a name as ${user}`) | |
} | |
logInfo('123', 'jarod') | |
logInfo(123, 'jarod') | |
// type allias | |
type Uid = number | string | undefined | |
function logDetails2(uid: Uid, item: string) { | |
console.log(`A product with ${uid} has a title as ${item}`) | |
} | |
function logInfo2(uid: Uid, user: string) { | |
console.log(`A user with ${uid} has a name as ${user}`) | |
} | |
logInfo2('123', 'jarod') | |
logInfo2(123, 'jarod') | |
type Platform = 'Windows' | 'Linux' | 'MacOS' | |
function handlePlatform(platform: Platform) { | |
return platform | |
} | |
handlePlatform('Windows') // work | |
handlePlatform('ios') // dont work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment