cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

Suggestion: include ts-optchain as example transformer #48

Closed wielrls closed 5 years ago

wielrls commented 5 years ago

We have built a custom transformer to support optional chaining in TypeScript: https://github.com/rimeto/ts-optchain

{ "transform": "ts-optchain/transform" }

ts-optchain/transform automatically converts the code:

  const obj: T = { /* ... */ };
  const value = oc(obj).propA.propB.propC(defaultValue);

...into:

  const obj: T = { /* ... */ };
  const value =
    (obj != null && obj.propA != null && obj.propA.propB != null && obj.propA.propB.propC != null)
      ? obj.propA.propB.propC
      : defaultValue;

Would appreciate a cross-link!

cevek commented 5 years ago

done!