In your Next.js TS project, you can store your custom type definitions (.d.tsΒ files) in theΒ typesΒ directory at the root level of your project (Convention)

my-nextjs-app/ 
β”œβ”€β”€ components/ 
β”œβ”€β”€ pages/ 
β”œβ”€β”€ styles/ 
β”œβ”€β”€ types/ 
β”‚   └── my-module.d.ts 
β”œβ”€β”€ utils/ 
β”œβ”€β”€ next.config.js 
β”œβ”€β”€ package.json 
β”œβ”€β”€ tsconfig.json 
└── yarn.lock`

TheΒ my-module.d.tsΒ file contains the type definitions for the my-module module you are using in your project.

Inform TypeScript of your custom types

To ensure that TypeScript can find and use your custom type definitions, you need to configure theΒ typeRootsΒ option in yourΒ tsconfig.jsonΒ file. Update theΒ tsconfig.jsonΒ file as follows:

{   
	"compilerOptions": {     
		"typeRoots": ["./types", "./node_modules/@types"]   
	},   
	// Other configuration options... 
}

By addingΒ "./types"Β to theΒ typeRootsΒ array, TypeScript will look for type definitions in theΒ typesΒ directory relative to your project’s root.