TS3 [Typescript] Generic - 1 function toObj(a: string, b: string): { a: string; b: string }; function toObj(a: number, b: number): { a: number; b: number }; function toObj(a: boolean, b: boolean): { a: boolean; b: boolean }; function toObj( a: string | number | boolean, b: string | number | boolean ): { a: string | number | boolean; b: string | number | boolean } { return { a, b }; } toObj("A", "B"); toObj(1, 2); toObj(true.. 2023. 11. 18. [Typescript] 타입추론 타입 스크립트에서 타입을 따로 명시하지 않아도 되는경우 1) 초기환된 변수 ex) let a= 'hello' 2) 기본값이 지정된 매개변수 ex) function join(a = '', b=''): string { return a+b;} 3) 반환이 있는 함수 ex) 위 함수의 return값은 당연히 string이 될것이라 추론을 할 수 있음 2023. 11. 12. [React + typescript] cannot be used as a JSX component React + ts로 간단한 프로젝트를 만드는데 이런 에러가 발생했다. 구글에 찾아봤는데 내 경우에 fit한 해결방법이 안보였다. import React from "react"; import { useAuthContext } from "../components/context/AuthContext"; import { Navigate } from "react-router-dom"; type ProtectedRouteProps = { children: React.ReactNode; requireAdmin?: boolean; }; const ProtectedRoute = ({ children, requireAdmin }: ProtectedRouteProps) => { const authContext = useA.. 2023. 7. 19. 이전 1 다음