From e8d71e4abd13c624d6e0fe354abb3b61573a8950 Mon Sep 17 00:00:00 2001 From: Aditya pradhan Date: Mon, 21 Jul 2025 00:13:48 +0530 Subject: [PATCH] docs: add section explaining Types global namespace usage (#97) --- docs/types-global-namespace.md | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/types-global-namespace.md diff --git a/docs/types-global-namespace.md b/docs/types-global-namespace.md new file mode 100644 index 0000000..e0417d7 --- /dev/null +++ b/docs/types-global-namespace.md @@ -0,0 +1,40 @@ +## Using the `Types` Global Namespace + +In a large-scale React + Redux + TypeScript project, it's often helpful to use the `Types` global namespace to share type definitions across your application. + +### ✅ Why Use a Global Namespace? + +- Central place to store common types like `User`, `Product`, etc. +- No need to import types in every file. +- Improves consistency and scalability. + +### 🔧 Example Setup + +1. Create a global declaration file: + +```ts +// src/types/global.d.ts +export {}; + +declare global { + namespace Types { + type User = { + id: string; + name: string; + email: string; + }; + } +} +### 💡 Usage Example + +Now you can use `Types` anywhere in your code **without importing**: + +```ts +const greet = (user: Types.User) => { + console.log(`Hello, ${user.name}`); +}; + +const total = (product: Types.Product) => { + return product.price * 2; +}; +