Registry / type-stubs / babel-plugin-ts-optchain

babel-plugin-ts-optchain

JSON →
library1.1.5jsnpmunverified

Babel plugin that transforms optional chaining expressions (e.g., `obj?.prop`) for TypeScript using the ts-optchain approach. Version 1.1.5 (latest) is stable but unmaintained since 2020. Provides an alternative to TypeScript's native optional chaining for environments that don't support it, by converting `?.` into `_` wrapped calls. Works only with Babel, not tsc. No dependencies. Not recommended for new projects; prefer native optional chaining.

npm install babel-plugin-ts-optchain
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TS-OP
B
babel-plugin-ts-optchain
type-stubsjavascriptv1.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
module.exports = { plugins: ['ts-optchain'] };
import plugin from 'babel-plugin-ts-optchain';
This is a Babel plugin, not meant to be imported directly. Add it to .babelrc or babel.config.js as a string.
default
module.exports = { plugins: ['ts-optchain'] };
import babelPluginTsOptchain from 'babel-plugin-ts-optchain';
The package has no default export; it's a Babel plugin referenced by name.
ts-optchain types
import { oc } from 'ts-optchain';
import oc from 'ts-optchain';
The companion 'ts-optchain' package provides the runtime `oc` function. Ensure both packages are installed: npm install ts-optchain babel-plugin-ts-optchain

Shows installation, Babel config, and usage with ts-optchain's oc function for safe optional access.

// Install: npm install --save-dev babel-plugin-ts-optchain ts-optchain // .babelrc { "plugins": ["ts-optchain"] } // Example TypeScript file import { oc } from 'ts-optchain'; const obj = { a: { b: 'hello' } }; const val = oc(obj).a.b(); // returns 'hello' const missing = oc(obj).x.y('default'); // returns 'default' // Compiled output uses the oc function console.log(val, missing);
Debug
Known issues
deprecatedPackage is effectively unmaintained since 2020. Use TypeScript 3.7+ native optional chaining (obj?.prop) when possible.
fix
Migrate to native optional chaining and remove babel-plugin-ts-optchain.
affects: >=1.0
gotchaRequires both 'babel-plugin-ts-optchain' and 'ts-optchain' packages to be installed. Missing one causes runtime errors.
fix
Run: npm install ts-optchain babel-plugin-ts-optchain
affects: all
deprecatedBabel plugin no longer necessary for TypeScript 3.7+. Native optional chaining is compile-time and more efficient.
fix
Remove the plugin and use TypeScript's native ?. operator.
affects: >=1.0
Errors
Common errors & fixes
SyntaxError: Unexpected token '.'
Babel is not set up to parse modern optional chaining syntax.
fix
Ensure babel.config.js includes the ts-optchain plugin and that you are using the correct Babel parser. Example: { plugins: ['ts-optchain'] }
Cannot find module 'ts-optchain'
Missing runtime dependency 'ts-optchain'.
fix
Install the package: npm install ts-optchain
TypeError: oc(...).a.b is not a function
Using oc() without calling the final property as a function (e.g., oc(obj).a.b instead of oc(obj).a.b()).
fix
Invoke the last property access as a function: oc(obj).a.b()
Upgrade
Version history
1.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
40
OpenAI (training)
1
Resources
babel-plugin-ts-optchain — npm install babel-plugin-ts-optchain · libregistry