코더 장군
강아지코더
코더 장군
전체 방문자
오늘
어제
  • 분류 전체보기 (67)
    • 프론트엔드 (24)
      • react (9)
      • html5 * css3 (1)
      • Javascript (10)
    • 개발일기 (36)
      • 알고리즘 (27)
      • 블록체인 (3)
      • mongoDB (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 비공개#일기
  • 일기#심리상담
  • 백준

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
코더 장군

강아지코더

프론트엔드/react

Typescript 병합 선언과 개별 선언

2022. 7. 15. 14:58

* 같은 파일에서 동일한 이름에 타입과 함수가 있으면 에러가 발생하지 않지만 import 해서 동일한 이름에 타입으로 가져와 사용한다면 에러가 발생한다.  

//todoList.tsx

import type { Mybodyinfo, TodoData, TodoAdd } from "@components/home/type";

.
.
.
// error ms : Individual declarations in merged declaration 
// 'TodoAdd' must be all exported or all local.ts(2395)

export const TodoAdd = (props: TodoAdd) => {
  return (
    <Button padding={props.padding ? props.padding : "10px 20px"} h="auto" bg="#CEEBEE" color="#5CBEC7" onClick={props.onClick}>
      <Flex flexDirection="column" alignItems="center" gap="5px" justifyContent="center">
        <>{props.Icon}</>
        <Text fontSize={props.fontSize ? props.fontSize : "10px"}>{props.text}</Text>
      </Flex>
    </Button>
  );
};

* 단순하게 타입으로 네임 동일에 문제라기 보다는 내보내기로 병합되는 항목이 아니라 가져오기가 로컬 선언과 병합될 수 없다는 것입니다.

그렇기 때문에 가져오기한 type을 export한 로컬 선언과 병합할려면 type 네임을 변경 해야한다. 

import type { Mybodyinfo, TodoData, TodoAdd as TodoAddInterface } from "@components/home/type";
.
.
.
export const TodoAdd = (props: TodoAddInterface) => {

* 네임스페이스로 해결하는 방법도 있지만 네임스페이스 자체를 권장하지 않기 때문에 사용하지 않았습니다. 

* 부족한 부분이 있으면 댓글로 알려주시길 바랍니다.

 

 

참조자료
https://www.merixstudio.com/blog/typescript-declaration-merging/

 

Declaration merging in TypeScript for regular devs | Merixstudio

Do you need to extend type declarations from a third-party library or use advanced abstractions? Use declaration merging!

www.merixstudio.com

https://stackoverflow.com/questions/58670409/individual-declarations-in-merged-declaration-departmentlistcomponent-must-be

 

Individual declarations in merged declaration 'DepartmentListComponent' must be all exported or all local.ts(2395) Routing compo

I have a problem with this code, I do it exactly like the video tutorial (I'm learning), but it doesn't work and calls for some declarations. It is possible that the code written in the guide is in...

stackoverflow.com

https://github.com/microsoft/TypeScript/issues/36684

 

3.8 RC Regression? "Individual declarations in merged declaration" · Issue #36684 · microsoft/TypeScript

TypeScript Version: 3.8.1-rc and nightly (3.8.0-dev.20200207) Search Terms: Individual declarations in merged declaration Code Two files: // ns.ts export type Type = {greet: string} export function...

github.com

 

'프론트엔드 > react' 카테고리의 다른 글

defaultProps  (0) 2022.07.15
Clean-up function  (0) 2022.01.24
[React] 컴포넌트 렌더링 이후 effect 수행하기  (0) 2022.01.24
moment를 적용 하면서  (0) 2022.01.12
AXIOS를 통한 서버연결  (0) 2021.12.12
    '프론트엔드/react' 카테고리의 다른 글
    • defaultProps
    • Clean-up function
    • [React] 컴포넌트 렌더링 이후 effect 수행하기
    • moment를 적용 하면서
    코더 장군
    코더 장군
    강아지 키우고 있는 소소한 개발자 성장기를 쓰는 일기장입니다

    티스토리툴바