Argument type { status: number } is not assignable to parameter type ResponseInit | undefined

//app/api/posts/route.js
import prisma from '@/prisma/prismadb'
import { NextResponse } from 'next/server'

export async function GET() {
  try {
    const posts = await prisma.post.findMany()

    return NextResponse.json(
      { message: 'STATIC GET FUNCTION WORKED SUCCESSFULLY', posts },
      { status: 200 },
    )
  } catch (error) {
    return NextResponse.json({ error: 'STATIC GET FUNCTION ERROR' }, { status: 500 })
  }
}

Whenever I do a CRUD operation, I get warnings like this. Am I using it incorrectly or is there another problem?

I don't use typescript project javascript

`Argument type { status: number } is not assignable to parameter type ResponseInit | undefined`

`Argument type { status: number } is not assignable to parameter type ResponseInit | undefined`

 

import Image from 'next/image'
import PostForm from '@/components/PostForm'
import PostContent from '@/components/PostContent'

const URL = process.env.NEXTAUTH_URL

async function getPosts() {
  try {
    const res = await fetch(`${URL}/api/posts`, { cache: 'no-store' })

    return await res.json()
  } catch (error) {
    console.log('Error loading topics', error)
  }
}

export default async function PostList() {
  const dataObject = await getPosts()
  const data = dataObject.posts

  console.log(dataObject.message || dataObject.error)

  return (
    <div className='flex items-center justify-center flex-col h-[calc(100vh-94px)]'>
      <Image src='/1.png' width={100} height={100} alt='logo' />
      <PostForm data={data} />
      {/*POSTS*/}
      <div className='mt-10 flex gap-5 flex-col lg:w-1/3 lg:mx-auto w-full'>
        {data.map((post) => (
          <div className='bg-slate-800 lg:rounded-t-lg' key={post.id}>
            <PostContent post={post.post} created={post.createdAt} id={post.id} />
          </div>
        ))}
      </div>
    </div>
  )
}

 

0
1 comment

Thank you for your help in providing all the details. We managed to reproduce the problem and have created a new ticket: https://youtrack.jetbrains.com/issue/WEB-66212/False-type-mismatch-errors-shown-for-NextResponse.json. Please subscribe to it to get notified of updates.

0

Please sign in to leave a comment.