首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在打字稿Gatsby中使用“Gatsby-插件-暗-模式”

如何在打字稿Gatsby中使用“Gatsby-插件-暗-模式”
EN

Stack Overflow用户
提问于 2021-04-09 04:37:38
回答 1查看 167关注 0票数 1

我想要实现的

在打字稿中使用“Gatsby插件-暗模式”

我至今所做的一切

yarn add gatsby-plugin-dark-mode

  • include‘gatsby-plugin--
    1. 在gatsby-config.js

    中安装“gatsby插件-暗模式”

代码语言:javascript
复制
module.exports = {
 plugins: ['gatsby-plugin-dark-mode'],
}

  1. 定义了ThemeToggler组件并导入了ThemeToggler

代码语言:javascript
复制
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.

我想要的&帮助

  1. :我是不是忽略了什么??
  2. 是Tyepscript Gatsby不支持的‘Gatsby -plugin-暗模式’??
  3. ,如果可以在Tyepscript Gatsby中使用‘Gatsby-plugin-暗模式’,那么告诉我我在这里缺少的东西。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-15 15:14:37

如果尚未创建全局接口文件,请在项目根目录中创建一个名为global.d.ts的全局接口文件,然后添加以下内容:

declare module 'gatsby-plugin-dark-mode';

对于任何抛出错误且没有已发布类型的包,都可以使用此代码段。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67015128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档