# Writing Advanced CWL JS Expressions in TypeScript

**URL:** <https://cwl.discourse.group/t/writing-advanced-cwl-js-expressions-in-typescript/755>\
**Category:** CWLCon 2023\
**Created:** [February 24, 2023, 1:44pm UTC](https://cwl.discourse.group/t/writing-advanced-cwl-js-expressions-in-typescript/755 "2023-02-24T13:44:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexiswl](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/alexiswl/32/93_2.png) [@alexiswl](https://cwl.discourse.group/u/alexiswl)\
**Post date:** [February 24, 2023, 1:44pm UTC](https://cwl.discourse.group/t/writing-advanced-cwl-js-expressions-in-typescript/755/1 "2023-02-24T13:44:56Z")

</div>

Presenter: [Alexis Lucattini](https://orcid.org/0000-0001-9754-647X), University of Melbourne Centre for Cancer Research (UMCCR) @alexiswl

[Schedule](https://cwl.discourse.group/t/schedule-of-confirmed-talks/753):

- Session 2: 🌍 🌏 (EMEA-APAC) Wednesday, March 1st 07:00 - 11:00 UTC / 16:00 - 20:00 Japanese Standard Time
- Session 3: 🌏 🌎 (APAC-Americas) Thursday, March 2nd 19:00 - 23:00 US EST  
Friday, March 3rd 00:00 - 04:00 UTC / 09:00 - 13:00 Japanese Standard Time

> Widespread use of CWL JavaScript Expressions is often restricted to simple one-line code fragments.
> 
> It is without dispute that writing complex, yet easily readable, ES5.1 conformant, JS code for CWL is inherently very difficult.
> 
> For many developers, interaction with CWL objects such as File, Dirent, Directory or custom-made schemas can prove to be a steep-learning curve.  
> It is therefore no surprise that writing complex CWL JS expressions is generally discouraged.  
> It is, however, sometimes necessary.
> 
> In this presentation we introduce the concept of writing our CWL JS expressions in TypeScript.
> 
> We will discuss the benefits of this approach, such as:
> 
> - type-hinting for CWL Objects,
> - compatible ‘transpilation’,
> - unit-testing with the jest framework
> - auto TypeScript-Interface creation for custom CWL Schemas.
> 
> We will view some simple and complex use-cases of CWL JS Expressions, the selection of open CWL TS packages and some caveats to consider for TypeScript in CWL.
> 
> We will conclude by noting that writing complex CWL JS expressions is a difficult task and alternative options should be considered. Using TypeScript may alleviate some existing challenges faced by developers writing CWL JS expressions.

- Slides: [https://bit.ly/typescript-in-cwl-powerpoint](https://bit.ly/typescript-in-cwl-powerpoint)
- CWL-ICA GitHub Repository: [https://github.com/umccr/cwl-ica](https://github.com/umccr/cwl-ica)
  - Releases Page: [https://github.com/umccr/cwl-ica/releases](https://github.com/umccr/cwl-ica/releases)
  - TypeScript Wiki Page: [https://github.com/umccr/cwl-ica/wiki/TypeScript](https://github.com/umccr/cwl-ica/wiki/TypeScript)
  - cwl-ica cli code base: [https://github.com/umccr/cwl-ica-cli](https://github.com/umccr/cwl-ica-cli)

- Jest Testing Framework: [https://jestjs.io/](https://jestjs.io/)
- Comparison of rabix cwlts vs cwl-ts-auto TypeScript modules: [https://github.com/common-workflow-lab/cwl-ts-auto/issues/23](https://github.com/common-workflow-lab/cwl-ts-auto/issues/23)

Please leave your questions for the presenter below!

[![](https://global.discourse-cdn.com/free1/uploads/cwl1/original/1X/748111ef0626da7029fa7a6e97bf7ffc83896c89.jpeg "Writing Advanced CWL JS Expressions in TypeScript") ](https://www.youtube.com/watch?v=Dn-zjkHtra8)

As an alternative to YouTube, this presentations is also available on ConfTube

https://conf.tube/videos/embed/d92d37eb-6d20-4aba-8c10-8efd480ea651

---

<div class="post-metadata">

**Author:** ![brunokinoshita](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/brunokinoshita/32/226_2.png) [@brunokinoshita](https://cwl.discourse.group/u/brunokinoshita)\
**Post date:** [March 1, 2023, 7:45am UTC](https://cwl.discourse.group/t/writing-advanced-cwl-js-expressions-in-typescript/755/2 "2023-03-01T07:45:08Z")

</div>

Hi Alexis!

Q. Just had a look at [GitHub - umccr/cwl-ica: A collection of cwl-ica workflows along with a user guide for the commands to use and contributions guide](https://github.com/umccr/cwl-ica), and I found some `package.json` files with ts, jest, etc. Is there any example that demonstrates CWL → TS with tests & coverage?

Q. You mentioned the `node_modules` in Yarn, but Yarn V3 and PnP could be a possible solution. (You answered that in the meeting, but asking here too for others/posterity).

Thanks!

---

<div class="post-metadata">

**Author:** ![alexiswl](https://yyz2.discourse-cdn.com/free1/user_avatar/cwl.discourse.group/alexiswl/32/93_2.png) [@alexiswl](https://cwl.discourse.group/u/alexiswl)\
**Post date:** [March 1, 2023, 10:42pm UTC](https://cwl.discourse.group/t/writing-advanced-cwl-js-expressions-in-typescript/755/3 "2023-03-01T22:42:49Z")

</div>

Hi Bruno,

> Is there any example that demonstrates CWL → TS with tests & coverage?

The only CWL → TS is the conversion of CWL schemas to TypeScript interfaces. These exist inside the schemas directory. I don’t have tests for this sorry, but if you start with [cwl-ica/bclconvert-settings\_\_4.0.3.ts](https://github.com/umccr/cwl-ica/blob/339c72cf06fda872806449a89a454907793a01ad/schemas/bclconvert-run-configuration/2.0.0--4.0.3/bclconvert-run-configuration__2.0.0--4.0.3.yaml) it shows it can handle very complex schemas.

For example tests showing TS to CWL expressions please checkout [the TypeScript wiki page](https://github.com/umccr/cwl-ica/wiki/TypeScript)

> but Yarn V3 and PnP could be a possible solution

Yes it sure could be, I’ll add something to the TypeScript wiki above, in the typescript expressions directory, yarn will create a file called .yarnrc.yml

You may set this to nodeLinker: pnp and see if that works for you?
