Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How using types.d.ts file in React & TypeScript project

i have React & TypeScript project. Here is i have folder structure in some component like:

 - ComponentFolder
  - index.tsx
  - types.d.ts
  - ChildComponent
    - index.tsx

I know that if i will put my types in types.d.ts file which in root of my component directory, I can use these types in childComponents in this directory.

So i tried;

my types.d.ts file:

export type CommonProps = {
  openItem: string;
  getValue: (e: React.MouseEvent) => void;
};

and in child component:

import * as React from "react";

const ChildComponent: React.FC<CommonProps> = (props) => {
  return (
    <div>
      {props.openItem}
    </div>
  );
};

export default ChildComponent;

But getting error:

cannot find CommonProps error.

How i know if i have some file d.ts in the directory i can use these types in this directory without import.

where i mistaken?

like image 344
ciz30 Avatar asked Nov 04 '25 05:11

ciz30


1 Answers

Remove the export keyword.

type CommonProps = {
  openItem: string;
  getValue: (e: React.MouseEvent) => void;
};
like image 181
kind user Avatar answered Nov 06 '25 23:11

kind user