簡體   English   中英

反應 + typescript 使用 CDN 腳本

[英]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.

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