Type '{ path: string; exact: boolean; component: () => Element; }' is not assignable to type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.
Property 'exact' does not exist on type 'IntrinsicAttributes & (PathRouteProps | LayoutRouteProps | IndexRouteProps)'.
→ react-router v6부터 exact를 더 이상 지원하지 않기 때문에 발생하는 문제이다. (exact가 없어진 이뉴는 대부분의 페이지들에서 exact=true가 적용되기 때문) 따라서 exact가 아닌 경우에는 <Route path="/settings/*" />과 같이 와일드카드(*)를 사용하면 된다.
그 외에 react-router v6 넘어오면서 바뀐 내용들
- route에서 component 대신 element (참고로 더 이상 component name을 그냥 넣어주면 안됨)
ex) element={<Home />} (X) / element={Home} (X)
- switch 대신 routes
- 페이지 이동할 때에는 const navigate = useNavigate(); + navigate("/~", {params});
- 어느 라우트에도 속하지않는 페이지를 만들려면(ex. 404 page) path='*;으로 지정한다.
Error: TypeScript emitted no output for
tsconfig.json으로 가서 noEmit이 true가 되어있지는 않는지 확인한다.
소수점 n번째 자리까지 출력하기
(방법 1)
let temp = number * (Math.pow(10, n))
temp = Math.ceil(temp)
const result = temp / (Math.pow(10, n))
(방법 2)
(a / b).toPrecision(n)
(방법 3)
(a / b).toFixed(n)
→ 2번, 3번 방법들은 모두 string을 return한다는 점에서 공통점을 지닌다. 그러나 toPrecision은 정수 자릿수까지 n에 포함되기 때문에 일반적인 경우에 사용이 부적합하다. toFixed는 정수 자릿수는 신경쓰지 않는다.
Object의 key 혹은 value들을 가지고 type checking을 하고 싶을 때
ex) const errorCodes = {
forbidden: 403,
notFound : 404,
} as const; // <----- add the <as const> here
type Keys = keyof typeof errorCodes; // "forbidden" | notFound
type Values = typeof KeyToVal[Keys]; // 403 | 404
as const 대신
const errorCodes = t({
forbidden: 403,
notFound : 404,
});
와 같은 방법도 가능하다.