본문 바로가기
프로그래밍/세팅 및 오류

[TypeScript] TSX에서 Custom Attribute를 사용하려고 했을 때 생기는 오류

by 노잼인간이라불립니다 2023. 12. 5.

1, 오류내용

Type '{ children: any; name: any; }' is not assignable to type 'DetailedHTMLProps<TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>'.
Property 'name' does not exist on type 'DetailedHTMLProps<TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>'.ts(2322)

 

2. 문제해결

https://ko.legacy.reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html

 

DOM Attributes in React 16 – React Blog

This blog site has been archived. Go to react.dev/blog to see the recent posts. In the past, React used to ignore unknown DOM attributes. If you wrote JSX with an attribute that React doesn’t recognize, React would just skip it. For example, this: would

ko.legacy.reactjs.org

 

커스텀 태그를 위해서는 data-xxx, aria-xxx의 방법으로 새롭게 태그를 작성하여 사용하면 된다.