打字稿不能使用animateMotion

时间:2019-01-13 16:11:28

标签: reactjs typescript svg svg-animate

当我尝试在React组件中使用animateMotion时,Typescript抱怨。

Property 'animateMotion' does not exist on type 'JSX.IntrinsicElements'.

Property 'mpath' does not exist on type 'JSX.IntrinsicElements'.

代码

import * as React from 'react'

type OrbitProps = {
  duration: number;
  radius: number;
}

export const Orbit: React.FunctionComponent<OrbitProps>= ({duration, radius}) => {
  const cx = 50
  const cy = 50
  return (
      <g>
        <path
          d={`M ${cx}, ${cy}
          m -${radius}, 0
          a ${radius},${radius} 0 1,0 ${radius*2},0
          a ${radius},${radius} 0 1,0 -${radius*2},0`}
          id="ellipse1"
        />
        <circle r="3">
          <animateMotion dur={`${duration}s`} repeatCount="indefinite">
            <mpath xlinkHref="#ellipse1" />
          </animateMotion>
        </circle>
      </g>
  )
}

2 个答案:

答案 0 :(得分:2)

编辑:

declare namespace JSX { 
  interface IntrinsicElements { 
    "animateMotion": any,
    "mpath": any, 
  } 
}

来源:https://www.typescriptlang.org/docs/handbook/jsx.html

答案 1 :(得分:0)

您已安装npm install @types/react --save吗?