gpt4 book ai didi

javascript - 访问 SyntheticEvent 目标上的 currentTime

转载 作者:行者123 更新时间:2023-11-30 20:03:30 25 4
gpt4 key购买 nike

在 vanilla React 中你得到 currentTime 就像

(e) => e.target.currentTime

在 typescript 中执行上述操作 ^3.1.6 结果

Property 'currentTime' does not exist on type 'EventTarget'

SyntheticEvent似乎没有在任何地方列出 EventTarget,所以我不知道如何获取 currentTime。 Typescript 库显示它是 already defined我的 tsconfig(通过 this fork 生成)看起来像

"compilerOptions": {
"lib": ["es6", "dom"]
}

部门:

"devDependencies": {
"@types/react-router": "^4.4.0",
"@types/react-router-dom": "^4.3.1",
"@types/jest": "^23.3.9",
"@types/node": "^10.12.2",
"@types/react": "^16.4.18",
"@types/react-dom": "^16.0.9",
"typescript": "^3.1.6"
}

最佳答案

找到答案 here

What you need to do is to cast the target to the specific element type with the properties you need.

所以要获得 currentTime 你需要做

(e: React.SyntheticEvent): void => {
const { currentTime } : { currentTime: number } = e.target as HTMLMediaElement;
}

关于javascript - 访问 SyntheticEvent 目标上的 currentTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53141673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com