* 같은 파일에서 동일한 이름에 타입과 함수가 있으면 에러가 발생하지 않지만 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
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 |