我正在使用 <span class="__cf_email__" data-cfemail="7033181102045e1a0330445e435e40">[email protected]</span>
开发 Nextjs 项目和 <span class="__cf_email__" data-cfemail="54263135372079373c3526203e27796614617a667a64">[email protected]</span>
而且,即使编译项目有效,WebStorm 仍表示存在类型错误。
这是一个 MRE (Nextjs):
// pages/index.tsx
import { Chart, registerables }
import { Line } from 'react-charts-j2'
const Index () => {
const chart = {
data: {
labels: ['foo', 'bar', 'foobar', 'foobaz']
datasets: [
{
label: 'Foo',
data: [0, 1, 2, 3]
}
]
}
}
return (
<Line data={chart.data} />
)
}
我尝试将数据和标签类型传递给 Line
例如:<Line<Array<number>, string>
,但这也不起作用。 IDE显示的错误如下:
Type {datasets: {data: number[], label: string}[], labels: string[]} is not assignable to type ChartData<"line", TData, TLabel>
环境:
- Nextjs:13.0.6
- react :18.2.0
- 节点:18.12.1
- typescript :^5.0.4
这与我的 IDE 或我的代码有关吗?
最佳答案
关于typescript - 为什么 WebStorm 显示 TypeScript 类型错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76185042/