Describe the bug
I get a TypeScript error when attempting to set the userData property of a MeshBasicMaterial instance at instantiation time, even though this property should be available from the parent Material class or MaterialParameters interface. I do not get an error when setting this property after instantiation.
To Reproduce
I am running three.js (r122) installed via npm:
import * as THREE from 'three';
...
const customUserData = {
foo: "bar"
};
const myMaterial = new THREE.MeshBasicMaterial({
color: 0xf7f7f7,
transparent: true,
opacity: 1,
side: THREE.BackSide,
userData: myCustomUserData
});
This returns the following error:
Argument of type '{ color: number; transparent: true; opacity: number; side: THREE.Side; userData: null; }' is not assignable to parameter of type 'MeshBasicMaterialParameters'.
Object literal may only specify known properties, and 'userData' does not exist in type 'MeshBasicMaterialParameters'. TS2345
Expected behavior
I should be able to specify userData at instantiation time, as MeshBasicMaterial inherits from Material, which should offer the userData property (perhaps via the MaterialParameters interface?).
As a workaround, the following did not yield an error:
let myMaterial = new THREE.MeshBasicMaterial({...});
myMaterial.userData = myCustomUserData;
Platform:
The TypeScript types are maintained in .d.ts files — Would you want to make a pull request to add this field below?
Sure, I can do that.
Most helpful comment
Sure, I can do that.