In my Next.js 13 project, I want to extend the Window object to have a property called gtag
在我的Next.js 13项目中,我想扩展Window对象,使其具有一个名为gtag的属性
In the root folder I had this index.d.ts
file like this
在根文件夹中,我有一个像这样的index.d.ts文件
index.d.ts
index.d.ts
declare module '*.svg' {
const content: any;
export const ReactComponent: any;
export default content;
}
I add the following lines to that
我在上面加了几行
export { }
declare module '*.svg' {
const content: any;
export const ReactComponent: any;
export default content;
}
declare global {
interface Window {
gtag: any;
}
}
Please note that export {}
line as well. Now my gtag is recognizing correctly. But the build failed with this error
请注意导出{}行。现在我的gtag识别正确了。但是生成失败,出现此错误
Module '".svg"' has no exported member 'ReactComponent'. Did you mean
to use 'import ReactComponent from ".svg"' instead?
So the conclusion is if I need to put export {}
to work gtag
. Same time not have export {}
to work svg.
因此得出的结论是,如果我需要将导出{}放入工作gtag。同时没有导出{}到工作svg。
How can I fix this with Next.js?
如何使用Next.js修复此问题?
更多回答
优秀答案推荐
Try this;
试试这个;
// Declare the module for SVG files first
declare module '*.svg' {
const content: any;
export const ReactComponent: any;
export default content;
}
// Declare the global interface for the window object
declare global {
interface Window {
gtag: any;
}
}
// Export an empty object to satisfy the export {}
export {};
更多回答
我是一名优秀的程序员,十分优秀!