Roll The Dice
close
프로필 배경
프로필 로고

Roll The Dice

  • 분류 전체보기 (107)
    • error (17)
    • Web (30)
      • TIL (15)
      • JAVA (1)
      • JS (13)
      • Python (1)
    • 알고리즘 (30)
    • 운영체제 (10)
    • 네트워크 (9)
    • ML DL (4)
      • TensorFlow 기초 (2)
      • Object Detection (2)
    • 면접 (0)
    • 회고 (0)
  • 홈
  • 태그
  • 방명록

[TypeScript] TSError: ⨯ Unable to compile TypeScript: Operator '+' cannot be applied to types 'T' and 'T'

generic 함수 여러 타입을 처리할 수 있는 generic 함수를 구현 두 개의 인자를 받아 값을 반환하는 함수를 구현 지시사항 generic T의 타입으로 number와 string, boolean만 가능하도록 제약조건을 추가하세요. T가 number라면 두 수를 더한 값을 반환하세요. T가 string이라면 두 문자열을 이어붙인 값을 반환하세요. T가 boolean이라면 두 값을 or 연산을 한 값을 반환하세요. 실행 결과 28 hello true 정답 코드 function add(a: T, b: T): T { if(typeof(a)==="boolean"){ return a||b; } return a + b; } console.log(add(13, 15)); console.log(add("hell..

  • format_list_bulleted Web/JS
  • · 2023. 10. 18.
  • textsms
  • navigate_before
  • 1
  • navigate_next
공지사항
전체 카테고리
  • 분류 전체보기 (107)
    • error (17)
    • Web (30)
      • TIL (15)
      • JAVA (1)
      • JS (13)
      • Python (1)
    • 알고리즘 (30)
    • 운영체제 (10)
    • 네트워크 (9)
    • ML DL (4)
      • TensorFlow 기초 (2)
      • Object Detection (2)
    • 면접 (0)
    • 회고 (0)
최근 글
인기 글
최근 댓글
태그
  • #메세지브로커
  • #이벤트브로커
  • #cpu게이트
  • #java22
  • #pm2 #vm
  • #Ram
  • #CPU
  • #node.js #express
  • #TS #typescript #generic
  • #캐시메모리
전체 방문자
오늘
어제
전체
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바