Last active
May 28, 2020 13:11
-
-
Save oukayuka/ca0134e2642d8a5405185fa96a795143 to your computer and use it in GitHub Desktop.
TypeScript Functions OverLoads Sample
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
class Brooch { | |
pentagram = 'Silver Crystal'; | |
} | |
type Compact = { | |
silverCrystal: boolean; | |
}; | |
class CosmicCompact implements Compact { | |
silverCrystal = true; | |
cosmicPower = true; | |
} | |
class CrisisCompact implements Compact { | |
silverCrystal = true; | |
moonChalice = true; | |
} | |
function transform(): void; | |
function transform(item: Brooch): void; | |
function transform(item: Compact): void; | |
function transform(item?: Brooch | Compact): void { | |
if (item instanceof Brooch) { | |
console.log('Moon crystal power💎, make up!!'); | |
} else if (item instanceof CosmicCompact) { | |
console.log('Moon cosmic power💖, make up!!!'); | |
} else if (item instanceof CrisisCompact) { | |
console.log('Moon crisis🏆, make up!'); | |
} else if (!item) { | |
console.log('Moon prisim power🌙, make up!'); | |
} else { | |
console.log('Item is fake...😖'); | |
} | |
} | |
transform(); | |
transform(new Brooch()); | |
transform(new CosmicCompact()); | |
transform(new CrisisCompact()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment