Skip to content

Instantly share code, notes, and snippets.

@maxencefrenette
Created June 27, 2018 18:13
Show Gist options
  • Save maxencefrenette/3595319a6c372214af65ad6f9d77804b to your computer and use it in GitHub Desktop.
Save maxencefrenette/3595319a6c372214af65ad6f9d77804b to your computer and use it in GitHub Desktop.
interface Cat {
readonly name: string | undefined;
}
function catPrinter(cat: Cat) {
if (cat.name === undefined) {
return;
}
console.log(cat.name.trim());
}
function delayedCatPrinter(cat: Cat) {
const cat2 = cat;
if (cat2.name === undefined) {
return;
}
setTimeout(() => console.log(cat2.name.trim()), 100);
// ...
}
function delayedPrinter(cat: string | undefined) {
const cat2 = cat;
if (cat2 === undefined) {
return;
}
setTimeout(() => console.log(cat2.trim()), 100);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment