Typescript не может использовать animateMotion - PullRequest
0 голосов
/ 13 января 2019

Typescript жалуется, когда я пытаюсь использовать animateMotion внутри компонента React.

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 голосов
/ 13 января 2019

Отредактировано:

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

Источник: https://www.typescriptlang.org/docs/handbook/jsx.html

0 голосов
/ 13 января 2019

Вы установили npm install @types/react --save?

...