Typescript Error - ts2339, ts2559, ts2741(+MutableRefObject) --react children

pyk0844·2023년 2월 15일
0

helpful post: TypeScript errors and how to fix them

TypeScript Common Errors

codesandbox for ts error

1. ts(2339), ts(2559)

error TS2339: Property --- does not exist on type ---.
error TS2559: Type --- has no properties in common with type ---.

codesandbox: src/ConflictTS2339_2559/Container 참고

--> 하위 컴포넌트에서 child prop type을 지정하지 않아 발생

What Happened to the FC Type's Implicit children Prop in @types/react v18?
React: Type {children: Element} has no properties in common with type IntrinsicAttributes
Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes'.ts(2559) error 해결하기

2. ts(2741)

error TS2741: Property --- is missing in type ‘{}’ but required in type ---.

codesandbox: src/ConflictTS2741/Container2741 참고

--> 하위 컴포넌트의 필수 프로퍼티를 전달하지 않아 발생

3. MutableRefObject

useRef<T>(initialValue: T): MutableRefObject<T>;

--> useRef를 로컬 변수 용도로 사용하는 경우

TypeScript React에서 useRef의 3가지 정의와 각각의 적절한 사용법

0개의 댓글