Error occurs when using vtkPixelSpaceCallbackMapper with TypeScript

I tried this example in typescript, but below error occured.

SphereAndLabels.ts:44:22 - error TS2345: Argument of type '(coordsList: any) => void' is not assignable to parameter of
type '() => any'.
  Target signature provides too few arguments. Expected 1 or more, but got 0.

44 psMapper.setCallback((coordsList) => {

Maybe lacking of type difinitions for parameters of callback in index.d.ts files causes this error.

/**
 * Set the callback function the mapper will call, during the rendering
 * process, with the screen coords of the points in dataset. The callback
 * function will have the following parameters:
 * 
 * // An array of 4-component arrays, in the index-order of the datasets points
 * 
 * coords: [
 *   [screenx, screeny, screenz, zBufValue],
 *   ...
 * ]

 * // The active camera of the renderer, in case you may need to compute alternate
 * // depth values for your dataset points.  Using the sphere mapper in your
 * // application code is one example where this may be useful, so that you can
 * // account for that mapper's radius when doing depth checks.
 * 
 * camera: vtkCamera

 * // The aspect ratio of the render view and depthBuffer
 * aspect: float

 * // A Uint8Array of size width * height * 4, where the zbuffer values are
 * // encoded in the red and green components of each pixel.  This will only
 * // be non-null after you call setUseZValues(true) on the mapper before
 * // rendering.
 * 
 * depthBuffer: Uint8Array
 * 
 * @param callback 
 */
setCallback(callback: () => any): boolean

I added paramters and types as below, then it works well.

	//setCallback(callback: () => any): boolean
	setCallback(callback: (coords: any, camera: vtkCamera, aspect: number, depthValues: number[]) => any): boolean	

Feel free to submit a PR with the proper type definition

1 Like