reactjs - 打字稿:谷歌“一键”找不到名称“googleyolo”
问题描述
我试图让谷歌一键使用打字稿,我得到的错误是Cannot find name 'googleyolo'.ts(2304)
<script src="https://smartlock.google.com/client"></script>
...
useEffect(() => {
const clientId = process.env.REACT_APP_GOOGLE_CLIENT_ID
const getID = async () => {
const credential = await googleyolo.retrieve({
// ^ error
supportedAuthMethods: ["https://accounts.google.com"],
supportedIdTokenProviders: [{ uri: "https://accounts.google.com", clientId }]
});
console.log(credential)
}
getID();
}, []);
我可以写一个界面
interface YoloInterface {
retrieve: any
cancelLastOperation: any
hint: any
disableAutoSignIn: any
}
但我不知道如何告诉 TypeScript?
解决方案
您应该像这样在模块顶部声明 googleyolo:
declare var googleyolo: any; // or any way you see fit
或者创建一个声明文件。