首页 > 解决方案 > 在 Vscode 中编辑 Typescript 文件中的 css 代码时,所有文本都是红色的,我该如何解决这个问题?

问题描述

这是正在发生的事情的图片 [1]:https ://i.stack.imgur.com/9yXUJ.png 这是代码。

export const GlobalStyle = createGlobalStyle`
  html {
    height: 100%;
  }
  body {
    background-image: url(${BGImage});
    background-size: cover;
    margin: 0;
    padding: 0 20px;
    display: flex;
    justify-content: center;
  }
  * {
    font-family: 'Catamaran', sans-serif;
    box-sizing: border-box;
  }
`;

标签: javascripthtmlcsstypescriptvisual-studio-code

解决方案


扩展vscode-styled-components可以帮助格式化和着色样式组件中的代码或不同文件中的类似代码,包括.tsx,上面的示例对我来说如下所示:

使用扩展名格式化的代码

红色下划线是由于缺少带下划线的变量的 TypeScript 类型/函数。


推荐阅读