Installation & Configuration
This guide covers how to install and configure the reTuple
utility and its associated validation tooling.
Installation
Section titled “Installation”You’ll need to install the utility package and the TypeScript plugin.
-
Install the utility (production dependency):
Installing dependencies… npm i @maxmorozoff/try-catch-tupleInstalling dependencies… yarn add @maxmorozoff/try-catch-tupleInstalling dependencies… pnpm add @maxmorozoff/try-catch-tupleInstalling dependencies… bun add @maxmorozoff/try-catch-tupleInstalling dependencies… ni @maxmorozoff/try-catch-tuple -
Install the TS plugin and
ts-patch
(dev dependencies):Installing dependencies… npm i -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescriptInstalling dependencies… yarn add -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescriptInstalling dependencies… pnpm add -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescriptInstalling dependencies… bun add -d @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescriptInstalling dependencies… ni -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescriptNote
ts-patch
is required if you want to use the build transformer for compile-time checks. If you only need IDE feedback (LSP), you can omit it.
Configuration (tsconfig.json
)
Section titled “Configuration (tsconfig.json)”The tooling is configured within your tsconfig.json
under compilerOptions.plugins
.
Combined LSP & Transformer (Recommended)
Section titled “Combined LSP & Transformer (Recommended)”This setup provides both real-time IDE feedback and build-time validation. It requires ts-patch
.
{ "compilerOptions": { // ... your other options "plugins": [ { "name": "@maxmorozoff/try-catch-tuple-ts-plugin", // For LSP "transform": "@maxmorozoff/try-catch-tuple-ts-plugin/transformer", // For Build // --- SHARED Configuration (applies to both) --- "errorLevel": "error", // Default: "error" "allowIgnoredError": true, // Default: true "checkWrappedCalls": true // Default: true } ] }}
LSP Plugin Only
Section titled “LSP Plugin Only”If you only want IDE feedback and don’t need the build-time transformer, use this configuration.
{ "compilerOptions": { // ... your other options "plugins": [ { "name": "@maxmorozoff/try-catch-tuple-ts-plugin", // --- Optional Configuration for LSP --- "errorLevel": "error", "allowIgnoredError": true, "checkWrappedCalls": true } ] }}
1. IDE (Language Service Plugin)
Section titled “1. IDE (Language Service Plugin)”To get real-time feedback in your editor (like VS Code):
- Select Workspace TypeScript Version: Ensure your editor is using your project’s installed version of TypeScript, not its own built-in version.
- In VS Code, open a
.ts
file and click the version number in the status bar, then select “Use Workspace Version”.
- In VS Code, open a
- Restart TS Server: After configuring the plugin, you must restart the TypeScript Server for the changes to take effect.
- In VS Code, open the Command Palette (
Ctrl+Shift+P
) and runTypeScript: Restart TS server
.
- In VS Code, open the Command Palette (
You should now see errors underlined in your editor with quick fixes available.
2. Build (Transformer)
Section titled “2. Build (Transformer)”To enable build-time checks, you need to use ts-patch
.
Method 1: Live Compiler
Section titled “Method 1: Live Compiler”The live compiler patches tsc
on-the-fly each time it is run.
- Command Line: Use
tspc
instead oftsc
to compile your project. - Tooling: For tools like
ts-node
,webpack
, orts-jest
, configure them to usets-patch/compiler
as the TypeScript compiler.
Method 2: Persistent Patch
Section titled “Method 2: Persistent Patch”This method modifies the TypeScript installation in your node_modules
directory. It has a lower overhead than the live compiler but requires a prepare
script to remain active after npm install
.
-
Install the patch:
Patching the TypeScript compiler… npx ts-patch installPatching the TypeScript compiler… yarn ts-patch installPatching the TypeScript compiler… pnpm ts-patch installPatching the TypeScript compiler… bunx ts-patch installPatching the TypeScript compiler… nlx ts-patch install -
Add
prepare
script topackage.json
:package.json {"scripts": {"prepare": "ts-patch install -s"}}
This ensures the patch is automatically reapplied whenever dependencies are installed. For more details, see the ts-patch documentation.