Overview of OAS Generator
typescript-axios or typescript-fetch.website·Indexed 32 days ago
https://hmos.dev/A technical blog by front-end engineer Hyunmo Ahn focusing on web development, featuring deep dives into Immer, React performance optimization, Next.js Docker configurations, i18next with TypeScript, and Open API Specification (OAS) generation.
typescript-axios or typescript-fetch.| Case | Description | Standalone | Custom Server |
|---|---|---|---|
| 1 | Basic Next.js build and run | ❌ | ❌ |
| 2 | Running in standalone mode | ✅ | ❌ |
| 3 | Using a custom server | ❌ | ✅ |
| 4 | Standalone + Custom Server | ✅ | ✅ |
oas-generator-cli to produce the final generated code. The tool supports custom code templates to fit specific project requirements.standalone output mode (which automatically copies traced files for a smaller build) and whether it utilizes a custom server. Choosing the right combination is critical for successful containerization.| Case | Description | Standalone | Custom Server |
|---|---|---|---|
| 1 | Basic Next.js build and execution | ❌ | ❌ |
| 2 | Execution in Standalone mode | ✅ | ❌ |
| 3 | Using a Custom Server | ❌ | ✅ |
| 4 | Standalone + Custom Server | ✅ | ✅ |
When using i18next with TypeScript, a standard translation function (tFunction) often lacks the precision to distinguish between a simple string return and a ReactElement return. To prevent runtime bugs (such as [object Object] appearing in HTML attributes like placeholder), the return type should be inferred based on two criteria:
\n), the function should return a ReactElement (since \n is typically converted to <br /> in React).{0}) include JSX elements (like <a> tags), the function should return a ReactElement regardless of the string content.This can be achieved using TypeScript 4.1+ Template Literal Types to analyze the i18n JSON keys and values at the type level.
i18next.t or a custom tFunction), the return type can vary between string and ReactElement based on the content of the translation key and the values passed to it. Specifically, if a translation contains newline characters (\n) or if JSX elements are passed as interpolation values, the result must be a ReactElement to be rendered correctly in React. If the type is not accurately inferred, passing an i18n result to a string-only attribute (like an HTML <input> placeholder) can result in [object Object] being displayed instead of the intended text.// Returns string
tFunction('simple-example')
// Returns ReactElement because of \n
tFunction('line-break-example')
// Returns ReactElement because a JSX element is passed as a value
tFunction('values-example', [<a href="/about">more</a>])| Case | Description | Standalone | Custom Server |
|---|---|---|---|
| 1 | Basic Next.js build and run | ❌ | ❌ |
| 2 | Running in standalone mode | ✅ | ❌ |
| 3 | Using a custom server | ❌ | ✅ |
| 4 | Standalone + Custom Server | ✅ | ✅ |
Immer maintains immutability by wrapping the base state in a Proxy object. It intercepts basic object operations (like get and set) to prevent direct modification of the original data.
Key internal mechanisms include:
base_: Stores the original data.copy_: Stores the updated data (a shallow copy created when a change is first detected).modified_ flag: A boolean tracker that indicates whether a specific object or property has been changed.get trap ensures that any nested object accessed is also returned as a Proxy, allowing Immer to track changes deep within the object tree.Immer allows developers to write mutable code to update state while maintaining immutability. It achieves this by wrapping the base state in a Proxy object.
Key internal mechanisms include:
get and set operations on the state.set operation occurs, Immer shallowly copies the original data (base_) to a new object (copy_) and applies the change there.modified_ flag is used to track if an object has been changed. If a child object is modified, the modified_ flag is set to true for that object and all its parents up to the root.Redux-devtools implements time-travel debugging using the following architectural patterns:
unliftStore and liftStore.liftAction objects with a PERFORM_ACTION type and sent to a liftReducer.liftReducer records every action and the resulting state. The application's actual state is derived by calling getState on the unliftStore for the state corresponding to the currently selected action index.liftReducer and delivering the resulting state of the desired point in time back to the application.