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
function sound(animal: Dog | Cat) { | |
if (animal instanceof Dog) { | |
// animal은 Dog로 추론됨. | |
animal.bark(); | |
animal.meow(); // error TS2339: Property 'meow' does not exist on type 'Dog'. | |
return; | |
} | |
if (animal instanceof Cat) { | |
// animal은 Cat으로 추론됨. | |
animal.bark(); // error TS2339: Property 'bark' does not exist on type 'Cat'. |
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 Dog { | |
bark = () => { | |
console.log('bark!'); | |
}; | |
} | |
class Cat { | |
meow = () => { | |
console.log('meow!'); | |
}; |
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
interface Window { | |
title: string; | |
} | |
interface Window { | |
ts: import("typescript"); | |
} | |
declare function getWindow(): Window; |
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 TBase = { | |
t: number; | |
}; | |
interface IBase { | |
i: number; | |
} | |
// extends 사용 | |
interface I1 extends TBase {} |
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
interface Human { | |
name: string; | |
age: number; | |
} | |
const henry: Human = { | |
name: '남현욱', | |
age: 20, | |
}; |
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
function checkNumberIsZero(par: number): boolean { | |
return par === 0; | |
} | |
checkNumberIsZero(0); // true | |
checkNumberIsZero([]); // Error! | |
checkNumberIsZero(""); // Error! | |
checkNumberIsZero(false); // Error! | |
checkNumberIsZero(this); // Error! |
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
// Problem 1 | |
const obj = { width: 10, height: 15 }; | |
const area = obj.width * obj.heigh; // NaN | |
// Problem 2 | |
function checkNumberIsZero(par) { | |
return par == 0; | |
} |
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
function pipe(...functions) { | |
return input => functions.reduce((value, func) => func(value), input); | |
} | |
function multiplyTwice(x) { | |
return x * 2; | |
} | |
function addFive(x) { | |
return x + 5; |
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
function pipe(...functions) { | |
return input => functions.reduce((value, func) => func(value), input); | |
} | |
function compose(...functions) { | |
return input => functions.reduceRight((value, func) => func(value), input); | |
} |
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
function createPage({ | |
title = '', // 해당 값이 없을 때 기본으로 사용할 값 | |
body = '', | |
tags = [], | |
actions = [], | |
} = {}) { /* ... */ } | |
// usage | |
createPage({ | |
title: 'Hello world!', |