[英]React + typescript using CDN script
我使用 reactjs 和 typescript。 我試圖在組件中使用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>
任何想法如何解決這個問題?
只需添加:
declare global {
interface Window { someScript: any }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.