首页 > 解决方案 > 即使代码已修复,Typescript 也会出现错误

问题描述

我有一个错字并调用了green[4500], 不存在(在 Material UI 中,但这并不重要)而不是green[500], 存在。

所以我得到了一个打字稿错误,因为Property '4500' does not exist on type......无论是什么类型的green. 是。

然后我修复它并保存它,我仍然得到错误。即使错误具有固定代码,但错误仍然存​​在。

Property '4500' does not exist on type '{ 50: "#e8f5e9"; 100: "#c8e6c9"; 200: "#a5d6a7"; 300: "#81c784"; 400: "#66bb6a"; 500: "#4caf50"; 600: "#43a047"; 700: "#388e3c"; 800: "#2e7d32"; 900: "#1b5e20"; A100: "#b9f6ca"; A200: "#69f0ae"; A400: "#00e676"; A700: "#00c853"; }'. Did you mean '400'?  TS2551

     6 | 
     7 | const StartButton = styled(Button)({
  >  8 |   background: green[500],
       |                     ^
     9 |   color: 'white'
    10 | })
    11 | const StopButton = styled(Button)({

重新启动服务器可以修复它,这并不奇怪。如果这有什么不同,我正在使用 WebStorm 并从运行菜单(而不是直接从终端)运行服务器。

为什么 Typescript 落后了?

标签: reactjstypescriptwebstorm

解决方案


推荐阅读