[React Typescript] Updating the Global Namespace for an Additional Attribute

I want to add a common attribute to dom element globally:

<>
  <div testId="123" />
  <audio testId="123" />
  <video testId="123" />
  <a testId="123" />
  <abbr testId="123" />
  <address testId="123" />
</>;

 

Solution:

declare global {
  namespace React {
    interface HTMLAttributes<T> {
      solutionTestId?: string;
    }
  }
}

 

posted @ 2023-08-24 14:52  Zhentiw  阅读(14)  评论(0)    收藏  举报