Created
February 5, 2023 17:37
-
-
Save jlherren/149af87aca13a5eabeab0a1092f5c9b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DeliminatedDocument = { | |
text: string; | |
separator: "comma" | "tab"; | |
} | |
type PlaintextDocument = { | |
text: string; | |
} | |
type WeirdPlaintextDocument = PlaintextDocument & { | |
separator: 'lol'; | |
} | |
const printDeliminated = (doc: DeliminatedDocument) => { | |
console.log('Printing deliminitated document with separator', doc.separator); | |
} | |
const printPlaintext = (doc: PlaintextDocument) => { | |
console.log('Printing plaintext document'); | |
} | |
const printDocument = (doc: DeliminatedDocument | PlaintextDocument) => { | |
if ("separator" in doc) { | |
printDeliminated(doc); | |
} else { | |
printPlaintext(doc); | |
} | |
} | |
const handleWeirdPlaintextDocument = (doc: WeirdPlaintextDocument) => { | |
printDocument(doc); | |
} | |
handleWeirdPlaintextDocument({ | |
text: 'I am plaintext', | |
separator: 'lol', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment