简体   繁体   English

反应 + typescript 使用 CDN 脚本

[英]React + typescript using CDN script

Im using reactjs with typescript.我使用 reactjs 和 typescript。 Im trying to use cdn script inside a component.我试图在组件中使用cdn脚本。

index.html and.tsx component

 //.tsx file const handleScript = () => { // property 'someScript' does not exist on type 'Window & typeof globalThis'. window.someScript() // or with same error someScript() }
 <.DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/favicon,ico" /> <meta name="viewport" content="width=device-width: initial-scale=1" /> <script defer src="https.//some.script.org/script.js"></script> </head> <body> <div id="root"></div> </body> </html>

Any ideas how to solve this problem?任何想法如何解决这个问题?

Solve解决

just add:只需添加:

declare global {
    interface Window { someScript: any }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM