簡體   English   中英

嘗試使用 TypeScript 訪問 A-frame 中的 Element.object3D 時出現“類型 'Element' 上不存在屬性 'object3D'”錯誤

[英]"Property 'object3D' does not exist on type 'Element'" error when trying to access Element.object3D in A-frame with TypeScript

首先,我是日本學生。 所以,請原諒我糟糕的英語。 我正在開發一個框架庫,現在在 TypeScript 中使用anime.js 制作動畫。 當我嘗試訪問 Element.object3D 以更新位置值時,TypeScript 生成“Property 'object3D' does not exist on type 'Element'”錯誤。 這是我的代碼。

function updateValue(target: Element, attr: Attribute, value: number) {
switch (attr) {
    case "PositionX":
        target.object3D.position.setX(value)
    case "PositionY":
        target.object3D.position.setY(value)
    case "PositionZ":
        target.object3D.position.setZ(value)

}

我意識到 Element 上不存在“object3D”,但是在導入 a-frame 時它存在。 我試圖 require("aframe") 但這個問題沒有解決。 對於這個問題的基本性質和我糟糕的英語,我深表歉意,但如果您能回答,我將不勝感激。

您可能需要安裝@types/aframe包,以便為您的 typescript 項目輸入類型。

之后,使用實體場景(我不知道哪一個是您在updateValue中收到的,但那兩個包含object3D

function updateValue(target: Entity, attr: Attribute, value: number) {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM