Skip to content

Elvis operator (aka safe navigation) implementation with typescript plugin.

Notifications You must be signed in to change notification settings

Acanguven/ts-safe-access

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-safe-access

Hacky way to implement elvis operator (aka safe navigation) with typescript plugin.

Module Transpiler

If you want to just get the corresponding JavaScript output given TypeScript sources. For this you can use ts.transpileModule to get a string => string transformation like below.

Custom Compiler

If you want get custom compiler only in addition to native tsc that's run custom transformer before compilation. Custom compiler that will take a list of TypeScript files and compile down to their corresponding JavaScript files.

Source

console.log(a.test?.way?.dd.cc?.uu);
console.log(ac?.test?.test2);
console.log(ac?.test[3]?.test2);
console.log(a?.test);
console.log(a.test?a.c?4:32:3)

Compiled

console.log((((a.test || {}).way || {}).dd.cc || {}).uu);
console.log(((ac || {}).test || {}).test2);
console.log(((ac || {}).test[3] || {}).test2);
console.log((a || {}).test);
console.log(a.test ? a.c ? 4 : 32 : 3);

Install

yarn add ts-safe-access
npm i ts-safe-access --save --dev

Usage

ttsc <input_file_name>.ts

Module transpiler example can be found here

Custom compiler example can be found here

About

Elvis operator (aka safe navigation) implementation with typescript plugin.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published