添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I try to change OrbitControls to TypeScript. How to solve this error:

error TS2345: Argument of type ‘any’ is not assignable to parameter of type ‘never’.
this.dispatchEvent( this._startEvent );

Minimal code that can reproduce the problem:

import {
    EventDispatcher
} from 'three';
const _startEvent = { type: 'start' };
const STATE = {
    NONE: - 1
let state = STATE.NONE;
class OrbitControls extends EventDispatcher {
    constructor( object, domElement ) {
        super();
    onMouseDown( event ) {
        if ( state !== STATE.NONE ) {
            this.dispatchEvent( this._startEvent );
export { OrbitControls };
    

pmndrs/three-stdlib/blob/eab87ab825a9edf7988acdb300851e824d2c1602/src/controls/OrbitControls.ts

import {
  EventDispatcher,
  Matrix4,
  MOUSE,
  OrthographicCamera,
  PerspectiveCamera,
  Quaternion,
  Spherical,
  TOUCH,
  Vector2,
  Vector3,
  Plane,
} from 'three'
const _ray = new Ray()
const _plane = new Plane()
const TILT_LIMIT = Math.cos(70 * (Math.PI / 180))
// This set of controls performs orbiting, dollying (zooming), and panning.
              

Thank you very much! That repository has all classes that I need. I can just copy/paste them to my projects.

They have solved the problem of this topic like this by adding @ts-ignore:

      // @ts-ignore
      scope.dispatchEvent(changeEvent)