250x250
Rainbow๐ŸŒˆCoder
My dev Note๐Ÿ“’
Rainbow๐ŸŒˆCoder
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (411)
    • ๊ณต์ง€์‚ฌํ•ญ (0)
    • Debugger (10)
      • Visual Studio Debugger (1)
      • Chrome DevTools (3)
      • Visual Studio Code Debugger (4)
      • eclipse (1)
      • intelliJ (1)
    • OOP (2)
      • OOP (2)
    • TypeScript (54)
      • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript (54)
    • Javascript (87)
      • Javascript (45)
      • Node.js (19)
      • React (5)
      • FE ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ค์ • (3)
      • React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ (6)
      • next.js (2)
      • pixi.js (7)
    • ๋งˆํฌ์—… (23)
      • Html & Css (23)
    • C# (80)
      • C# (12)
      • ์ด๊ฒƒ์ด C#์ด๋‹ค (68)
    • C++ (30)
      • c++ (27)
      • win api (3)
    • Unity (18)
      • Unity(๊ธฐ์ดˆ) (8)
      • Unity(C#์ค‘๊ธ‰) (5)
      • ์œ ๋‹ˆํ‹ฐ ํฌํ†ค(๋„คํŠธ์›Œํฌ) (4)
      • unity c# MyCode (1)
    • Java & Spring (29)
      • Java (11)
      • ์Šคํ”„๋ง (8)
      • Java Algorithm (9)
      • Javs Data Structures (1)
    • ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (15)
      • ์ž๋ฃŒ๊ตฌ์กฐ (5)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (10)
    • ํ˜•์ƒ๊ด€๋ฆฌ (15)
      • Git (11)
      • ์†Œ์ŠคํŠธ๋ฆฌ (3)
    • ๊ทธ๋ž˜ํ”ฝ์Šค (7)
      • WebGl (7)
    • AWS (3)
      • aws (3)
    • ๋ฆฌ๋ˆ…์Šค (5)
      • ๋ฆฌ๋ˆ…์Šค (5)
    • ์ฑ… ๋ฆฌ๋ทฐ (13)
      • ํด๋ฆฐ์ฝ”๋“œ(์ฑ…๋ฆฌ๋ทฐ) (3)
      • ์œ ์ง€๋ณด์ˆ˜๊ฐ€๋Šฅํ•œ์ฝ”๋”ฉ์˜๊ธฐ์ˆ C#ํŽธ(์ฑ…๋ฆฌ๋ทฐ) (1)
      • ๋ฆฌํŒฉํ† ๋ง(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธํŒ) (9)
    • Server (2)
      • ๊ฒŒ์ž„ ์„œ๋ฒ„(๋„คํŠธ์›Œํฌ, ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ,OS) (2)
    • ์„ค๊ณ„, ์•„ํ‚คํ…์ณ (4)
    • ํŒŒ์ด์ฌ (5)
    • ๋””์ž์ธํŒจํ„ด (2)
    • mocha (2)
    • Jest (1)
    • Spine (1)
    • ์ธ๊ณต์ง€๋Šฅ (1)
      • ํ˜ผ์ž๊ณต๋ถ€ํ•˜๋Š”๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹ (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • ์œ„์ž„
  • ์ปดํฌ์ง€์…˜
  • MySQL
  • ใ…ฃใ„ท

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
Rainbow๐ŸŒˆCoder

My dev Note๐Ÿ“’

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ค๋ฆญ ํด๋ž˜์Šค
TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ค๋ฆญ ํด๋ž˜์Šค

2022. 4. 25. 19:03
728x90
//๋‹ค๋ฅธ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ
//either: a or b
interface Either<T, U> {
  left: () => T;
  right: () => U;
}
class SimpleEither<T, U> implements Either<T, U> {
  constructor(private leftValue: T, private rightValue: U) {}
  left(): T {
    return this.leftValue;
  }
  right(): U {
    return this.rightValue;
  }
}

const either = new SimpleEither(4, { name: "ํ™๊ธธ๋™", age: 18 });
console.log(either.left()); //4
console.log(either.right()); //ํ™๊ธธ๋™โ€‹
//either: a or b
interface Either {
  left: () => number;
  right: () => number;
}
class SimpleEither implements Either {
  constructor(private leftValue: number, private rightValue: number) {}
  left(): number {
    return this.leftValue;
  }
  right(): number {
    return this.rightValue;
  }
}

const either = new SimpleEither(4, 5);
console.log(either.left()); //4
console.log(either.right()); //5

 

๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ

{
  //๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ
  //either: a or b
  interface Either<T> {
    left: () => T;
    right: () => T;
  }
  class SimpleEither<T> implements Either<T> {
    constructor(private leftValue: T, private rightValue: T) {}
    left(): T {
      return this.leftValue;
    }
    right(): T {
      return this.rightValue;
    }
  }

  const either: Either<string> = new SimpleEither("์‹ฌ์ฒญ์ด", "ํ™ฉ์ง„์ด");
  console.log(either.left()); //์‹ฌ์ฒญ์ด
  console.log(either.right()); //ํ™ฉ์ง„์ด
}

๋ช…์‹œ ์•ˆ ํ•ด์ฃผ์–ด๋„ ๋จ

{
  //๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ
  //either: a or b
  interface Either<T> {
    left: () => T;
    right: () => T;
  }
  class SimpleEither<T> implements Either<T> {
    constructor(private leftValue: T, private rightValue: T) {}
    left(): T {
      return this.leftValue;
    }
    right(): T {
      return this.rightValue;
    }
  }

  const either = new SimpleEither("์‹ฌ์ฒญ์ด", "ํ™ฉ์ง„์ด");
  console.log(either.left()); //์‹ฌ์ฒญ์ด
  console.log(either.right()); //ํ™ฉ์ง„์ด
}

 

 

๋‹ค๋ฅธ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ

{
  //๋‹ค๋ฅธ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ
  //either: a or b
  interface Either<T, U> {
    left: () => T;
    right: () => U;
  }
  class SimpleEither<T, U> implements Either<T, U> {
    constructor(private leftValue: T, private rightValue: U) {}
    left(): T {
      return this.leftValue;
    }
    right(): U {
      return this.rightValue;
    }
  }

  const either: Either<number, string> = new SimpleEither(4, "ํ™๊ธธ๋™");
  console.log(either.left()); //4
  console.log(either.right()); //ํ™๊ธธ๋™

๋ช…์‹œ ์•ˆ ํ•ด์ฃผ์–ด๋„ ๋จ

  //๋‹ค๋ฅธ ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋ฐ”๊พธ๊ธฐ
  //either: a or b
  interface Either<T, U> {
    left: () => T;
    right: () => U;
  }
  class SimpleEither<T, U> implements Either<T, U> {
    constructor(private leftValue: T, private rightValue: U) {}
    left(): T {
      return this.leftValue;
    }
    right(): U {
      return this.rightValue;
    }
  }

  const either = new SimpleEither(4, "ํ™๊ธธ๋™");
  console.log(either.left()); //4
  console.log(either.right()); //ํ™๊ธธ๋™
}

์‹ฌ์ง€์–ด ์˜ค๋ธŒ์ ํŠธ ํƒ€์ž…๋„ ๋จ.

์ด์ฒ˜๋Ÿผ ์ œ๋„ค๋ฆญ์„ ์ด์šฉํ•˜๋ฉด ํ™œ์šฉ์„ฑ ๋†’์€ ํ•จ์ˆ˜์™€ ํ™œ์šฉ์„ฑ ๋†’์€ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90

'TypeScript > ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ค๋ฆญ ํƒ€์ž… ๋ช…์‹œ ์ฃผ์˜์‚ฌํ•ญ  (0) 2022.04.26
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๊ณตํ™ˆ] User-Defined Type Guards  (0) 2022.04.26
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ filter์™€ map  (0) 2022.04.25
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ๊ฐ์ฒด์ง€ํ–ฅ์ ์œผ๋กœ Generic Stack<T> ํด๋ž˜์Šค ๊ตฌํ˜„ํ•˜๊ธฐ  (0) 2022.04.25
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ค๋ฆญ  (0) 2022.04.25
    'TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์ œ๋„ค๋ฆญ ํƒ€์ž… ๋ช…์‹œ ์ฃผ์˜์‚ฌํ•ญ
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๊ณตํ™ˆ] User-Defined Type Guards
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ filter์™€ map
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ๊ฐ์ฒด์ง€ํ–ฅ์ ์œผ๋กœ Generic Stack<T> ํด๋ž˜์Šค ๊ตฌํ˜„ํ•˜๊ธฐ
    Rainbow๐ŸŒˆCoder
    Rainbow๐ŸŒˆCoder
    ๋ชฐ๋ผ๋„ ๊ฒฐ๊ตญ์€ ์•„๋Š” ๊ฐœ๋ฐœ์ž, ๊ทธ๋Ÿฐ ์‚ฌ๋žŒ์ด ๋˜๊ธฐ ์œ„ํ•œ ๋งค์ผ์˜ ํ•œ๊ฑธ์Œ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”