Skip to content

docs: add section explaining Types global namespace usage (#97) #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/types-global-namespace.md
Original file line number Diff line number Diff line change
@@ -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;
};
Comment on lines +37 to +39

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The product type is not defined in the global namespace example above. This could lead to confusion for readers trying to implement the example. Either define the Product type in the global namespace or change the example to use the User type to align with the provided example.

Suggested change
const total = (product: Types.Product) => {
return product.price * 2;
};
const total = (user: Types.User) => {
return user.id.length * 2; // Example using User type
};