Skip to content

Commit

Permalink
update docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosir committed Mar 16, 2024
1 parent c695bfd commit 207fbe9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions website/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ When creating types we try to think of how they would best **describe our code**
Being expressive and keeping types as **narrow as possible** brings benefits to the codebase:

- Increased Type Safety - Catch errors at compile-time, since narrowed types provide more specific information about the shape and behavior of your data.
- Improved Code Clarity - Reduced cognitive load by providing clearer boundaries and constraints on your data which makes your code easier to understand by other developers.
- Improved Code Clarity - Cognitive load is reduced by providing clearer boundaries and constraints on your data which makes your code easier to understand by other developers.
- Easier Refactoring - Refactor with confidence, since types are narrow, making changes to your code becomes less risky.
- Optimized Performance - In some cases, narrow types can help the TypeScript compiler generate more optimized JavaScript code.

Expand Down Expand Up @@ -134,21 +134,21 @@ Template literal types have many applicable use cases e.g. API endpoints, routin

```ts
// ❌ Avoid
const userEndpoint = '/api/usersss'; // Type 'string' - Since typo, route 'usersss' doesn't exist it will result in runtime error
const userEndpoint = '/api/usersss'; // Type 'string' - Since typo 'usersss', route doesn't exist and results in runtime error
// ✅ Use
type ApiRoute = 'users' | 'posts' | 'comments';
type ApiEndpoint = `/api/${ApiRoute}`;
const userEndpoint: ApiEndpoint = '/api/users';

// ❌ Avoid
const homeTitleTranslation = 'translation.homesss.title'; // Type 'string' - Since typo, translations page 'homesss' doesn't exist it will result in runtime error
const homeTitleTranslation = 'translation.homesss.title'; // Type 'string' - Since typo 'homesss', translation doesn't exist and results in runtime error
// ✅ Use
type LocaleKeyPages = 'home' | 'about' | 'contact';
type TranslationKey = `translation.${LocaleKeyPages}.${string}`;
const homeTitleTranslation: TranslationKey = 'translation.home.title';

// ❌ Avoid
const color = 'blue-450'; // Type 'string' - Since color 'blue-450' doesn't exist it will result in runtime error
const color = 'blue-450'; // Type 'string' - Since color 'blue-450' doesn't exist and results in runtime error
// ✅ Use
type BaseColor = 'blue' | 'red' | 'yellow' | 'gray';
type Variant = 50 | 100 | 200 | 300 | 400;
Expand Down

0 comments on commit 207fbe9

Please sign in to comment.