Skip to content
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

docs: Add guidelines for TypeScript Utility Types usage #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lucioerlan
Copy link

This pull request presents a practical guide on how to use TypeScript's Utility Types effectively. We cover essential types like Partial<T>, Readonly<Type>, Record<Keys, Type>, Pick<Type, Keys>, and Omit<Type, Keys>, which are fundamental in my day-to-day programming.

They are super useful for improving typing in various situations, from manipulating objects to defining interfaces for components. With them, we achieve fine control over our data, avoiding those annoying typing errors and making our code clearer and easier to maintain.

References:
https://www.typescriptlang.org/docs/handbook/utility-types.html

@@ -1913,6 +1913,143 @@ export type OrderList = {
}
```

### 11.7 TypeScript Utility Types
Copy link
Contributor

@rogigs rogigs Dec 14, 2023

Choose a reason for hiding this comment

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

Great ideas @lucioerlan 💡

What do you think about Typeof Type Operator ?

I've been using those points who you showed. And I've been use too the typeof to the case typing utils, for instance

Screenshot 2023-12-14 054838

Typescript inferred the item as

{
    title: string;
    images: {
        name: string;
        legend: string;
    }[];
}

More about Type Manipulation: https://www.typescriptlang.org/docs/handbook/2/types-from-types.html

Copy link
Author

Choose a reason for hiding this comment

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

tks @rogigs o/

it's beneficial because it ensures that your types are tight and evolve with your data structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants