我正在尝试让Google一键式使用打字稿,我得到的错误是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?
答案 0 :(得分:1)
您应该像这样在模块顶部声明googleyolo:
declare var googleyolo: any; // or any way you see fit
或创建一个声明文件。