最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React with Typescript: Property 'name' does not exist on type 'DetailedHTMLProps<HTM

programmeradmin0浏览0评论

I started using React with Typescript and I'm trying to add a "name" property to a "div" but Typescript is plaining about that and won't allow me to add it because that property doesn't exist.

This is the full message I get back:

Type '{ children: Element[]; name: string; className: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
  Property 'name' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.ts(2322)

How can I solve it? Here is an example of the .tsx file:

import React from "react";

export default function TestComponent() {
    return <div name="ponent-name">Test</div>;
}

I'm using the library react-scroll that requires a name property on the ponent.

I started using React with Typescript and I'm trying to add a "name" property to a "div" but Typescript is plaining about that and won't allow me to add it because that property doesn't exist.

This is the full message I get back:

Type '{ children: Element[]; name: string; className: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
  Property 'name' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.ts(2322)

How can I solve it? Here is an example of the .tsx file:

import React from "react";

export default function TestComponent() {
    return <div name="ponent-name">Test</div>;
}

I'm using the library react-scroll that requires a name property on the ponent.

Share Improve this question edited May 17, 2022 at 12:49 Dave asked May 17, 2022 at 12:36 DaveDave 2,2104 gold badges20 silver badges40 bronze badges 3
  • 1 Delete name="ponent-name" from the source code.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论