Skip to content

Commit

Permalink
update docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosir committed Dec 14, 2024
1 parent 66e0cc6 commit 50c3709
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions website/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,6 @@ Discriminated unions advantages:
- Discriminated unions make refactoring and maintenance easier by providing a centralized definition of related types. When adding or modifying types within the union, the compiler reports any inconsistencies throughout the codebase.
- IDEs can leverage discriminated unions to provide better autocompletion and type inference.

### Return Types

<Rule
prefix="Including return type annotations is highly encouraged, although not required"
href="https://typescript-eslint.io/rules/explicit-function-return-type/"
>{`"@typescript-eslint/explicit-function-return-type": "error"`}</Rule>

Consider benefits when explicitly typing the return value of a function:

- Return values makes it clear and easy to understand to any calling code what type is returned.
- In the case where there is no return value, the calling code doesn't try to use the undefined value when it shouldn't.
- Surface potential type errors faster in the future if there are code changes that change the return type of the function.
- Easier to refactor, since it ensures that the return value is assigned to a variable of the correct type.
- Similar to writing tests before implementation (TDD), defining function arguments and return type, gives you the opportunity to discuss the feature functionality and its interface ahead of implementation.
- Although type inference is very convenient, adding return types can save TypeScript compiler a lot of work.

### Type-Safe Constants with satisfies

The `as const satisfies` syntax is a powerful TypeScript feature that combines strict type-checking and immutability for constants. It is particularly useful when defining constants that need to conform to a specific type.
Expand Down Expand Up @@ -335,6 +319,22 @@ const iconColor: Color = 'blue-400';
const customColor: Color = '#AD3128';
```

### Return Types

<Rule
prefix="Including return type annotations is highly encouraged, although not required"
href="https://typescript-eslint.io/rules/explicit-function-return-type/"
>{`"@typescript-eslint/explicit-function-return-type": "error"`}</Rule>

Consider benefits when explicitly typing the return value of a function:

- Return values makes it clear and easy to understand to any calling code what type is returned.
- In the case where there is no return value, the calling code doesn't try to use the undefined value when it shouldn't.
- Surface potential type errors faster in the future if there are code changes that change the return type of the function.
- Easier to refactor, since it ensures that the return value is assigned to a variable of the correct type.
- Similar to writing tests before implementation (TDD), defining function arguments and return type, gives you the opportunity to discuss the feature functionality and its interface ahead of implementation.
- Although type inference is very convenient, adding return types can save TypeScript compiler a lot of work.

### Type any & unknown

`any` data type must not be used as it represents literally “any” value that TypeScript defaults to and skips type checking since it cannot infer the type. As such, `any` is dangerous, it can mask severe programming errors.
Expand Down

0 comments on commit 50c3709

Please sign in to comment.