diff --git a/website/src/pages/index.mdx b/website/src/pages/index.mdx index 4867d75..4b81dad 100644 --- a/website/src/pages/index.mdx +++ b/website/src/pages/index.mdx @@ -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 - -{`"@typescript-eslint/explicit-function-return-type": "error"`} - -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. @@ -335,6 +319,22 @@ const iconColor: Color = 'blue-400'; const customColor: Color = '#AD3128'; ``` +### Return Types + +{`"@typescript-eslint/explicit-function-return-type": "error"`} + +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.