我想要实现的
在打字稿中使用“Gatsby插件-暗模式”
我至今所做的一切
yarn add gatsby-plugin-dark-mode
中安装“gatsby插件-暗模式”
module.exports = {
plugins: ['gatsby-plugin-dark-mode'],
}import React from 'react'
import { ThemeToggler } from 'gatsby-plugin-dark-mode'
class MyComponent extends React.Component {
render() {
return (
<ThemeToggler>
{({ theme, toggleTheme }) => (
<label>
<input
type="checkbox"
onChange={e => toggleTheme(e.target.checked ? 'dark' : 'light')}
checked={theme === 'dark'}
/>{' '}
Dark mode
</label>
)}
</ThemeToggler>
)
}
}然后..。
Could not find a declaration file for module 'gatsby-plugin-dark-mode'. '/Desktop/my-blog/gatsby-casper/node_modules/gatsby-plugin-dark-mode/index.js' implicitly has an 'any' type.
我想要的&帮助
发布于 2021-04-15 15:14:37
如果尚未创建全局接口文件,请在项目根目录中创建一个名为global.d.ts的全局接口文件,然后添加以下内容:
declare module 'gatsby-plugin-dark-mode';
对于任何抛出错误且没有已发布类型的包,都可以使用此代码段。
https://stackoverflow.com/questions/67015128
复制相似问题