inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Phát triển blog công nghệ với Gatsby dựa trên React

Tạo danh mục và hiển thị các mục bài đăng theo danh mục

다른 부분에서 오류가 안나는데 {post.map 부분이 계속 오류가 납니다.

293

hwangcc10185997

6 câu hỏi đã được viết

1

-das

import React, { FunctionComponent } from 'react'
import styled from '@emotion/styled'
import PostItem from 'components/Main/PostItem'
import { PostListItemType } from 'types/PostItem.types'

export type PostType = {
  node: {
    id: string
    frontmatter: {
      title: string
      summary: string
      date: string
      categories: string[]
      thumbnail: {
        publicURL: string
      }
    }
  }
}


type PostListProps = {
  posts: PostListItemType[]
}



const PostListWrapper = styled.div`
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 20px;
  width: 768px;
  margin: 0 auto;
  padding: 50px 0 100px;

  @media (max-width: 768px) {
    grid-template-columns: 1fr;
    width: 100%;
    padding: 50px 20px;
  }
`

const PostList: FunctionComponent<PostListProps> = function ({ posts }) {
  return (
    <PostListWrapper>
      {posts.map(
        ({
          node: { id, frontmatter },
        }: PostType) => (
          <PostItem
            {...frontmatter}
            link="https://www.google.co.kr/"
            key={id}
          />
        ),
      )}
    </PostListWrapper>
  )
}

export default PostList
 
 
색칠한 부분이
 
Argument of type '({ node: { id, frontmatter }, }: PostType) => JSX.Element' is not assignable to parameter of type '(value: PostListItemType, index: number, array: PostListItemType[]) => Element'.
  Types of parameters '__0' and 'value' are incompatible.
    Type 'PostListItemType' is not assignable to type 'PostType'.
      The types of 'node.frontmatter.thumbnail' are incompatible between these types.
        Property 'publicURL' is missing in type '{ childImageSharp: { gatsbyImageData: IGatsbyImageData; }; }' but required in type '{ publicURL: string; }'.
 
이런 에러를 띄웁니다... 계속 처음부터 따라해봤는데 요부분만 해결이 안되요...

blog Gatsby

Câu trả lời 1

0

hwangcc10185997

https://github.com/madmanforces/blog 
혹시몰라서 깃허브 링크 남겨놓습니다!

1

ji5485

안녕하세요, hwangcc1018님!

너무 늦게 질문을 확인해서 죄송하다는 말씀 먼저 드리고 싶습니다 ㅠㅠ

혹시 문제점을 해결하셨을까요?

일단 에러 메시지를 확인해봤을 때에는 타입이 맞지 않아서 생기는 문제로 보입니다.

바로 이전 챕터인 gatsby-plugin-image 라이브러리로 최적화된 썸네일 사진 띄워주기 부분에서

PostListItemType에 대한 타입 정의를 변경했는데, 이 과정에서 publicURL 이라는 프로퍼티가 삭제되었습니다!

해당 챕터를 다시 복습하고 오시는 것을 추천드립니다 :)

쿼리오류 Field "thumbnail" must not have a selection...

1

862

1

타입스크립트를 설정할 때 jsxPragma 옵션을 뺀 이유는 무엇인가요?

1

595

1

마지막 배포 부분 질문드립니다!

1

619

1

'[username]/[username].github.io' -> 'username/reponame'

0

342

0

IntersectionObserver deploy( gatsby build) 시 오류(자답)

1

395

1

PostHead.tsx BackgroundImage 동작오류(자답)

1

294

0

19강 인피니티 스크롤 IntersectionObserver 코드 위치 수정이 필요합니다.

1

407

1

썸네일 이미지 제작 및 학습 방법 관련 문의

1

443

1

배포 후 포스트 업로드 방법

1

383

1

배포 질문이요!

1

523

1

gatsby develop 오류

1

938

1

깃허브 레퍼지토리 질문드려요

1

342

1

특정 게시글을 클릭하여 상세 페이지로 넘어가는 과정과 SPA에 관한 질문

1

284

1

Unhandled Runtime Error 가 뜹니다

0

506

2

sign in with GitHub 클릭 시

1

394

3

동작 반복 시 오류

1

350

2

const BackgroundImage 질문

1

212

1

오타 문의

1

303

2

Props로 받아 포스트 데이터 출력하기가 안됩니다.

1

201

1

index.tsx allMarkdownRemark 에러..

0

593

2

스네이크 케이스로 변수명을 짓는 이유

1

248

1

'Tagged Template Literal 방식을 통해 정의한 CSS 적용 방법'에서 발생하는 문제

3

350

2

상단 이미지를 썸네일 사용하지않고 다른 이미지를 쓰고싶습니다

1

284

1

여기까지 했는데 runtime 에러가 발생합니다

2

283

1