Typescript Jupyter Notebooks: How to set them up.

Deno is the solution, but I had some trouble so thought I should share the solution.

ACGoff
3 min readApr 29, 2024

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.

Virtual envs saved me.

  1. 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.)
  2. Activate Virtual Environment: source .venv/bin/activate - This command activates the previously created virtual environment.
  3. Upgrade pip: python3 -m pip install --upgrade pip - Ensures that the Python package manager (pip) is up-to-date.
  4. 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.
  5. Install IPython Kernel: pip install ipykernel - This command installs the IPython kernel, which allows IPython to be used as a Jupyter kernel.
  6. 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.
  7. Install Deno Jupyter Kernel: deno jupyter --install - This command installs the Deno kernel for Jupyter, enabling support for running TypeScript code in Jupyter notebooks.
  8. Activate Deno Jupyter Kernel: deno jupyter --unstable - This command activates the Deno kernel for Jupyter, making it available for use in notebooks.
  9. 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.

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:

The result is type checking in that block.

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…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (1)

What are your thoughts?

I found that the code runs just fine, but the types aren't actually checked? Is there an additional step to get type checking working?