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?