Typescript Jupyter Notebooks: How to set them up.
Deno is the solution, but I had some trouble so thought I should share the solution.
I came across this by Kyle Kelley and was in love. Finally I could experiement in TS, not python and then rewrite to TS.
But.
![](https://miro.medium.com/v2/resize:fit:700/1*-kSce8GdlgPrhsXP6R3TCQ.png)
Virtual envs saved me.
- Create a Virtual Environment:
python3.10 -m venv .venv
- This command creates a virtual environment for Python, which helps isolate package installations and dependencies. (Make sure you have and are using python3.) - Activate Virtual Environment:
source .venv/bin/activate
- This command activates the previously created virtual environment. - Upgrade pip:
python3 -m pip install --upgrade pip
- Ensures that the Python package manager (pip) is up-to-date. - Install IPython:
pip install ipython
- IPython is a powerful interactive Python shell that provides additional features and enhancements over the default Python interpreter. It is super python. - Install IPython Kernel:
pip install ipykernel
- This command installs the IPython kernel, which allows IPython to be used as a Jupyter kernel. - Install Deno:
curl -fsSL https://deno.land/install.sh | sh
- This command downloads and installs the Deno runtime, which is required for running TypeScript code in Jupyter notebooks. Don’t just trust me a random person on the internel. Check out deno.com. - Install Deno Jupyter Kernel:
deno jupyter --install
- This command installs the Deno kernel for Jupyter, enabling support for running TypeScript code in Jupyter notebooks. - Activate Deno Jupyter Kernel:
deno jupyter --unstable
- This command activates the Deno kernel for Jupyter, making it available for use in notebooks. - Select Deno Kernel in Notebook: You should select the Deno kernel from the available kernels list. I use VScode and needed to install the default kernel extensions.
![](https://miro.medium.com/v2/resize:fit:700/0*hbRE7LfxPQRPtbF5.gif)
From here on Kyle’s post is fantastic! https://blog.jupyter.org/bringing-modern-javascript-to-the-jupyter-notebook-fc998095081e
Type checking while writing
The power of Typescript is to have your types checked before needing to run it. Tim Gent mentioned this. Here is how to fix that — install an extension:
![](https://miro.medium.com/v2/resize:fit:700/1*IJl8d58G-lkX1W1K4r9NNA.png)
The result is type checking in that block.
![](https://miro.medium.com/v2/resize:fit:700/1*_LoePpclQSkhhOS6zriEBw.png)
The only issue is that each block is treated as a separate script, which means if you have common types going across blocks, this gets painful.
If you know a solution — let me know!
But for now…
![](https://miro.medium.com/v2/1*TZJZOQcO1a_-e4AvXtwjmg.png)