Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Typescript组件运行正常,但表示存在错误,因为它无法识别存在的属性_Javascript_Typescript_Properties - Fatal编程技术网

Javascript Typescript组件运行正常,但表示存在错误,因为它无法识别存在的属性

Javascript Typescript组件运行正常,但表示存在错误,因为它无法识别存在的属性,javascript,typescript,properties,Javascript,Typescript,Properties,我使用three.js库在屏幕上绘制图像。当我创建particles=THREE.point(几何体、材质)类型脚本时,表示particles.geometry.vertices中不存在顶点,但当我运行模块时,所有内容都会按应有的方式加载和响应,此外,它还会给我一个错误,即顶点不存在,如果它们不存在,我就不会绘制该图像 几何体有一个称为顶点的属性,当我通过三个点(几何体、材质)创建对象粒子时;我从几何体中获取所有顶点,并通过执行此操作来访问它们。particles.geometry.vertic

我使用three.js库在屏幕上绘制图像。当我创建particles=THREE.point(几何体、材质)类型脚本时,表示particles.geometry.vertices中不存在顶点,但当我运行模块时,所有内容都会按应有的方式加载和响应,此外,它还会给我一个错误,即顶点不存在,如果它们不存在,我就不会绘制该图像

几何体有一个称为顶点的属性,当我通过三个点(几何体、材质)创建对象粒子时;我从几何体中获取所有顶点,并通过执行此操作来访问它们。particles.geometry.vertices,但typescript表示,即使该属性有效,几何体中也不存在该属性

错误图片,即使一切都按其应执行: 文本错误:

[at-loader] ./ClientApp/app/components/shared/backgroundScene/backgroundScene.component.ts:146:53 
    TS2339: Property 'vertices' does not exist on type 'Geometry | BufferGeometry'.
  Property 'vertices' does not exist on type 'BufferGeometry'.
[at-loader] ./ClientApp/app/components/shared/backgroundScene/backgroundScene.component.ts:147:56 
    TS2339: Property 'vertices' does not exist on type 'Geometry | BufferGeometry'.
  Property 'vertices' does not exist on type 'BufferGeometry'.
[at-loader] ./ClientApp/app/components/shared/backgroundScene/backgroundScene.component.ts:152:33 
    TS2339: Property 'verticesNeedUpdate' does not exist on type 'Geometry | BufferGeometry'.
  Property 'verticesNeedUpdate' does not exist on type 'BufferGeometry'.
渲染中提供了绘制表示顶点不存在的图像的源代码,drawImage仅显示了如何添加到粒子。一切正常,我只是不明白为什么在一切正常的情况下我会出现这些错误。如果你知道如何得到打字,这样我就可以看到我的对象中的这些属性,让我知道。如果你想知道的话,我有三个J和打字机,这些都很好用。我只是在访问对象的属性时遇到了问题,当属性存在并且typescript说它不存在时,但当我运行代码时,我可以看到它确实存在

public render() {
    this.renderer.render(this.scene, this.camera);

    // Draw image to screen
    for (var i = 0, j = this.particles.geometry.vertices.length; i < j; i++) {
        var particle:any = this.particles.geometry.vertices[i];
        particle.x += (particle.destination.x - particle.x) * particle.speed;
        particle.y += (particle.destination.y - particle.y) * particle.speed;
        particle.z += (particle.destination.z - particle.z) * particle.speed;
    }
    this.particles.geometry.verticesNeedUpdate = true;
}

public drawImage() {

    // Create vertices to draw the image.
    for (var y = 0, y2 = this.imageData.height; y < y2; y += 2) {
        for (var x = 0, x2 = this.imageData.width; x < x2; x += 2) {
            if (this.imageData.data[(x * 4 + y * 4 * this.imageData.width) + 3] > 128) {

                let vertex:any = new THREE.Vector3();
                vertex.x = Math.random() * 1000 - 500;
                vertex.y = Math.random() * 1000 - 500;
                vertex.z = -Math.random() * 500;

                vertex.destination = {
                    x: x - this.imageData.width / 2,
                    y: -y + this.imageData.height / 2,
                    z: 0
                };

                vertex.speed = Math.random() / 200 + 0.015;

                this.geometry.vertices.push(vertex);
            }
        }
    }
    this.particles = new THREE.Points(this.geometry, this.material);
    this.scene.add(this.particles);

    requestAnimationFrame(this.render);
}
public render(){
this.renderer.render(this.scene,this.camera);
//将图像绘制到屏幕
对于(var i=0,j=this.particles.geometry.vertices.length;i128){
让顶点:any=新的3.Vector3();
vertex.x=Math.random()*1000-500;
vertex.y=Math.random()*1000-500;
vertex.z=-Math.random()*500;
vertex.destination={
x:x-this.imageData.width/2,
y:-y+this.imageData.height/2,
z:0
};
vertex.speed=Math.random()/200+0.015;
这个.geometry.vertex.push(顶点);
}
}
}
this.particles=新的三个点(this.geometry,this.material);
this.scene.add(this.particles);
requestAnimationFrame(this.render);
}

我找到的修复不是最干净的,但我明确地将粒子投射到for循环中表示顶点不存在的任何位置。我变了

原件:

this.particles.geometry.vertices.length;
修正:

然后在我的tsconfig中,我将noImplicitAny标志设置为true

"noImplicitAny": true
"noImplicitAny": true