I'm currently working on a React project using TypeScript and I come across a very stupid problem and on top of that very annoying...
For example I create a dummy component called Page that need a page of type Page as props:
interface Props {
page: Page
}
export interface Page {
id: number
category: PageCategory
path: string
name: string
}
const Page: React.FunctionComponent<Props> = (props) => {
...
return (
...
<h1>{ props.page.name }<h1/>
...
export default Page
So far no problem but they're coming as soon as I decide to import the component with the type:
import Page, { Page } from './component/Page' // ts-error: 'Duplicate identifier 'Page''
So in order to avoid this problem I added the prefix I to all my interfaces like IPage but I'm sure there's a more elegant way to do it. How do you handle that?
PagegetsanytypeBut real solution is to give different names for different thingsyeah sure but what would be an other name for the typePage? Because the object is like aPagePageandconst Pageclash together. As Aleksey says, just give them different names.