我有一个结构化的项目:
export interface Project{
id: String,
title: String,
description: String,
image?: any,
languages: String[]
}
当我尝试映射语言数组时,如下所示:
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import Head from 'next/head'
import Image from 'next/image'
import { multipleProjects } from '../../test/projects'
import { Project as ProjectType } from '../../assets/types/types'
export default function Project() {
const router = useRouter()
const { id } = router.query
const [project, setProject] = useState<ProjectType>(null)
useEffect(() => {
const _project = multipleProjects.find(p => p.id === id)
if (_project) setProject(_project)
}, [])
if (!project) return "No project"
return (
<div className="h-screen def-background pt-16">
<Head>
<title>Project: </title>
</Head>
<div className="flex w-8/12 mx-auto mb-auto mt-24 flex-col justify-center items-center text-gray-200 font-mono">
<p className="text-center text-3xl font-bold tracking-wide text-gray-300 mx-4 p-2">{project.title}</p>
<div className="w-full h-72 relative m-8 p-4">
<Image
src={project.image}
alt={`Picture of the ${project.title}`}
layout='fill'
/>
</div>
<div className="w-full mx-12 p-4 text-left text-indent flex-grow">
{project.description}
</div>
{project.languages?.map((language, index) => {
return (
<div key={index} className="self-end flex gap-2 italic mr-8 mt-12 p-2 text-gray-600 text-sm">
{language}
</div>
)
})}
</div>
</div>
)
}
它抛出一个Excessive stack depth comparing types 'FlatArray<Arr, ?>' and 'FlatArray<Arr, ?>'
错误。可能的原因是什么?
我遇到了this issue,它告诉我降级VSCode的二手TS版本,但是有人想出了其他解决方案吗?
发布于 2021-03-24 02:19:50
显然,TS版本4.3.0-dev
有一个问题,我必须将VSCode使用的TS版本更改为4.2.3
的workspace
版本。偶然发现了一两种其他方法,但不幸的是,this issue是唯一有效的解决方案
耶,找到了一个不同的解决方法
<>
{project.languages?.map((language, index) => {
return (
<div key={index} className="self-end flex gap-2 italic mr-8 mt-12 p-2 text-gray-600 text-sm">
{language}
</div>
)
})}
</>
显然,添加片段可以暂时解决这个问题。
https://stackoverflow.com/questions/66768822
复制相似问题