4

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?

1 Answer 1

6

Remove the export keyword.

type CommonProps = {
  openItem: string;
  getValue: (e: React.MouseEvent) => void;
};
Sign up to request clarification or add additional context in comments.

4 Comments

or import the type from it location
@felixmosh Not really, the whole target about types.dev.ts is to be able to use interfaces without a need to import it.
Where can I find documentation about this? My problem is that if I try to import types, it also stops working. Using the import or export keyword breaks auto-type-discovery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.