본문 바로가기

부트캠프교육중301

[TS] 제네릭의 타입에 제한을 두는 경우 function lonTextLength(text: T): T { console.log(text.length); return text; } 이렇게만 하면 length부분에서 오류가 발생한다. 여기서 제네릭의 타입에도 제한을 두게 되면 이런식으로 function lonTextLength(text: T[]): T[] { console.log(text.length); return text; } 이렇게 하면 오류가 발생하지 않는다. lonTextLength(['hi', 'abc']); interface LengthType { length: number; } function lonTextLength2(text: T): T { text.length; return text; } 이렇게 하는건 제네릭은 LengthTy.. 2023. 8. 16.
[TS] interface에 제네릭을 선언하는 경우 그냥 interface를 사용하는 경우 interface Dropdown { value: string; selected: boolean; } const obj: Dropdown = { value: 'abc', selected: false }; interface에 제네릭을 선언한 경우 interface Dropdown { value: T; selected: boolean; } const obj: Dropdown = { value: 'abc', selected: false }; const obj: Dropdown = { value: 124, selected: false }; 그래서 interface Email { value: string; selected: boolean; } interface Product.. 2023. 8. 16.
[TS] 제네릭이란 function logText(text: T):T { console.log(text); return text; } logText('하이'); text의 타입은 하이라는 문자열이다. 반환하는값도 문자열이된다. function logText(text){ console.log(text); return text; } 저기서의 T는 logText라는 함수에서 T라는 타입을 받을거야 라는 의미이다. function logText(text: T){ console.log(text); return text; } 그걸 먼저 파라미터의 타입으로 쓰겠다. function logText(text: T): T{ console.log(text); return text; } 그리고 그걸 리턴할때도 쓰겠다. function logTe.. 2023. 8. 16.
[JS] 노마드코더 getElementById - string을 전달받는 함수 - html에서 id를 통해 element를 찾아준다. - getElementById란 함수를 통해 id로 element를 가져올수 있다. document.getElementById("title") title이라고 써있는 자리에는 id를 써야 하는데 string이어야 한다!!! querySelector - element를 css방식으로 검색할수 있다. - querySelector에는 hello가 classname이라는 것과 그 안의 h1을 명시해줘야한다. - getElementByName이면 hello만 써도된다. document.querySelector(".hello h1"); getElementsByClassName("hello") query.. 2023. 8. 16.