In my quest to optimize my TypeScript type definitions, I have scoured countless pages for the best approach.
- In the past, I kept a
typings.ts
file tucked away in my project, importing types into each file as needed using:
import {IMyCustomType} from './typings';
Within my typings file, I would declare types like so:
export interface IMyCustomType {...}
- Upon discovering this boilerplate: https://github.com/rokoroku/react-redux-typescript-boilerplate/tree/master/types, I noticed they utilize a
models.d.ts
file within atypes
directory at the root of their projects.
Rather than using
export interface IMyCustomType {..}
, they opt for declare interface IMyCustomType {..}
This setup presents a significant advantage: no need to import types explicitly in every file as the interfaces are available project-wide.
Questions:
1) Will all **/*.d.ts
files be automatically imported during compilation?
2) Is it advisable to use declare
and grant universal access to types throughout the project?
3) Is there a standard location and naming convention for housing type definitions?
Essentially, I aim to have global interfaces effortlessly accessible across my project without manual imports. Should I pursue this, and if so, how should I configure my project to achieve it?
UPDATE
Following discussions with my team, most opposed the idea of ambient types, opting instead to import types on demand. To streamline this process, we rely on our IDEs to handle automatic type imports.