-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
771d910
commit de9a1b5
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Config File | ||
|
||
When we talk about config file, it look like it's simpest feature while writing the code, however, | ||
behind the scene, they need to be designed with complex logic and type interface to ensure that the config file is type-safe. | ||
|
||
## Using Simple Object | ||
|
||
For example: | ||
|
||
In next.js, they use `next.config.mjs` to configure the next.js project. | ||
|
||
```ts | ||
// @ts-check | ||
|
||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
/* config options here */ | ||
} | ||
|
||
export default nextConfig | ||
``` | ||
|
||
## Using Function as a Config | ||
|
||
For example: | ||
|
||
In Vite or Vitest, they use `defineConfig` to configure the project. | ||
|
||
```ts | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
/* config options here */ | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Intro | ||
|
||
Many Frameworks provide better type-safe support for TypeScript, this section will provide technique and design pattern that most framework apply type-safe. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# What's Type-safe? | ||
|
||
Most community said that **type-safe** a lot, but no one try to define it. So, I will try to define it. | ||
|
||
Type-safe is a design pattern that provide a way to ensure that the data type is correct and consistent in the program. This pattern is very useful in modern programming language like TypeScript, where the type system is very powerful and can be used to ensure the correctness of the program. | ||
|
||
## Characteristics of Type-safe | ||
|
||
Many libraries and frameworks provide type-safe support, here is some characteristics of type-safe when the they claim that they are type-safe: | ||
|
||
- **Generic**: They use generic types | ||
- **Literal**: They use literal types | ||
- **Builder Pattern**: They use builder pattern | ||
- TBA |