Generic

Generic์ด๋ž€?

์–ด๋–ค ํƒ€์ž…์ด ์˜ฌ ์ง€ ๋ฏธ๋ฆฌ ์•Œ ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ์—์„œ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด๋‘๊ณ , ๋ฐ›์€ ํƒ€์ž…์œผ๋กœ ํƒ€์ž…์„ ๋Œ€์ฒดํ•˜๋Š” ๋ฌธ๋ฒ•์ž…๋‹ˆ๋‹ค.

function

function checkNotNull<T>(arg: T | null): T {
    if (arg == null) {
      throw new Error('not valid number!');
    }
    return arg;
  }
  const number = checkNotNull(123);
const boal: boolean = checkNotNull(true);

Last updated

Was this helpful?