Search code examples
reactjstypescripttsx

Typescript React type Attribute


While I make write code with Typescript + React, I found some error.

When I make type/value in <a> tag attribute, I get compile Error.

<a value='Hello' type='button'>Search</a>

This code get occur error

TS2339:Property 'value' does not exist on type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.

How can I solve this compile problem? I search few hours but I cannot get solution :(


Solution

  • Because value is not a valid HTML attribute for the <a> element. I think the best would be to use an attribute like <a data-value="Hello"> instead of trying to extend the AnchorHTMLAttributes interface.