Skip to content

Instantly share code, notes, and snippets.

View hw0k's full-sized avatar
🎯

Hyunwook Nam hw0k

🎯
  • localhost
  • 06:23 (UTC +09:00)
View GitHub Profile
@hw0k
hw0k / example.ts
Created January 17, 2021 09:32
TN 2
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'.
@hw0k
hw0k / example.ts
Last active January 17, 2021 09:23
TN 1
class Dog {
bark = () => {
console.log('bark!');
};
}
class Cat {
meow = () => {
console.log('meow!');
};
interface Window {
title: string;
}
interface Window {
ts: import("typescript");
}
declare function getWindow(): Window;
type TBase = {
t: number;
};
interface IBase {
i: number;
}
// extends 사용
interface I1 extends TBase {}
@hw0k
hw0k / human.ts
Last active October 4, 2020 09:47
TvI 1
interface Human {
name: string;
age: number;
}
const henry: Human = {
name: '남현욱',
age: 20,
};
@hw0k
hw0k / problem.ts
Created August 30, 2020 11:29
TSB 2
function checkNumberIsZero(par: number): boolean {
return par === 0;
}
checkNumberIsZero(0); // true
checkNumberIsZero([]); // Error!
checkNumberIsZero(""); // Error!
checkNumberIsZero(false); // Error!
checkNumberIsZero(this); // Error!
@hw0k
hw0k / problem.js
Created August 30, 2020 11:28
TSB 1
// Problem 1
const obj = { width: 10, height: 15 };
const area = obj.width * obj.heigh; // NaN
// Problem 2
function checkNumberIsZero(par) {
return par == 0;
}
@hw0k
hw0k / number.js
Created June 28, 2020 10:59
FND 9
function pipe(...functions) {
return input => functions.reduce((value, func) => func(value), input);
}
function multiplyTwice(x) {
return x * 2;
}
function addFive(x) {
return x + 5;
function pipe(...functions) {
return input => functions.reduce((value, func) => func(value), input);
}
function compose(...functions) {
return input => functions.reduceRight((value, func) => func(value), input);
}
function createPage({
title = '', // 해당 값이 없을 때 기본으로 사용할 값
body = '',
tags = [],
actions = [],
} = {}) { /* ... */ }
// usage
createPage({
title: 'Hello world!',