반응형
ts 사용중 위 에러가 뜨면 type지정을 통해 해결 가능합니다.
react에서 useSelector를 사용하는 경우를 보겠습니다.
# error 발생
const todos = useSelector(state => state.user);
# useSelector 타입 지정
const todos = useSelector<Record<string, string>>(state => state.user);
이상입니다
'개발 > typescript' 카테고리의 다른 글
[TS] Catch clause variable type annotation must be 'any' or 'unknown' if specified. (0) | 2022.07.21 |
---|---|
[Typescript] Module '"react-router-dom"' has no exported member 'useHistory'. (0) | 2022.06.03 |
type concat (0) | 2022.05.02 |
typescript+pwa 구현하기 (0) | 2021.04.29 |
typescript docs 번역본 #5 (Unions and Intersection Types) (0) | 2021.01.26 |