FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Python FDEs face only three truly new ideas in a TypeScript repo

Shape-based typing, Promises and npm are the new ground; the rest maps onto Python, plus one type check worth running before every merge.

ShareLinkedInFacebookX

In brief

  • Working JavaScript is valid TypeScript, so type checking can be switched on gradually, with no rewrite.
  • An async function always returns a Promise. Use its result without `await` and you hold a Promise instead of the data, so let tsc check every place where that result is read.
  • Node can run .ts files directly, but it only strips the types and checks nothing, so `tsc` still belongs in an `npm run` script before every merge.
Two code panels side by side. The "Before" panel: const user = getUser(id) carries error marker 1, and await sendMail(user.email) carries markers 2 and 3. The "After" panel: adds await (1, missing await), adds if (!user) return (2, user may be undefined), adds if (user.email === null) return (3, email may be null), and only then calls await sendMail(user.email). Matching lines in the two panels sit on the same row.
Add await and turn on strictNullChecks, and tsc reports three errors in turn. Each is a real data case the old code ignored.

On Monday morning you get access to a client’s backend repo. You have written Python for five years, and this repo is Node written in TypeScript. An endpoint that sends notification emails sometimes sends nothing, and the log holds a single line: undefined.

An FDE cannot reply “our team doesn’t do Node.” The client needs the bug fixed this week, on its own stack. The good news is that many of the concepts you will meet have Python counterparts. What is genuinely new comes down to three things: shape-based typing, Promises and npm.

You know more than you think

The official TypeScript documentation is explicit: working JavaScript code is also TypeScript code. For an FDE this has practical value, because you can add types to a client’s code one file at a time instead of asking permission to rewrite a whole module.

The syntax is familiar too. Type annotations follow the variable name, like Python type hints: function getUser(id: string). TypeScript infers types in many cases, so you annotate less than you might expect. And any behaves like Python’s Any: it switches checking off. The documentation advises against it, because a value of type any is not checked at all.

In Python In TypeScript/Node
x: str | None x: string | null
Any any (best avoided)
coroutine, await Promise, await
asyncio event loop Node’s event loop
requirements and dev-requirements dependencies and devDependencies
lock file package-lock.json

Types are matched by shape

This is the biggest shift in thinking. Python compares types by class name by default. TypeScript uses structural typing: two objects with the same shape count as the same type, whoever declared them.

So in a client’s repo you will see few class declarations and plenty of type User = { id: string; email: string | null }. Any object with both fields is accepted as a User, including JSON freshly parsed from an API.

Union types come with one rule worth remembering: TypeScript allows an operation only if it is valid for every member of the union. With string | null, you cannot call .toLowerCase() until you have checked that the value is not null.

With strictNullChecks on, every value that might be null or undefined must be checked before you use a property or method on it, much as you must check for None before using an Optional value in Python. The strict flag in tsconfig bundles these stricter checks together, and you should turn it on.

A Promise is Node’s awaitable

According to MDN, a Promise is an object returned by an asynchronous function that represents the current state of the operation. If you have written asyncio, the model is familiar: Node runs JavaScript on a single thread by default, and the event loop lets it perform non-blocking I/O.

The trap sits in one short sentence of the documentation: an async function always returns a Promise. Call one and forget await, and you are holding a promise of data, not the data. When reading someone else’s code, a missing await is very hard to spot by eye.

Fixing the client’s bug, step by step

Back to the email endpoint. Suppose the code looks like this:

type User = { id: string; email: string | null };

async function getUser(id: string): Promise<User | undefined> {
  const row = await db.findById(id);
  return row ?? undefined;
}

export async function notify(id: string) {
  const user = getUser(id);      // missing await
  await sendMail(user.email);    // user is a Promise, not a User
}

Here tsc rejects the user.email line even without strict, because a Promise has no email property. This is the easy case: the async function’s result is used on the very next line, so there is a mistyped operation for the compiler to catch.

The other two cases are harder. If someone casts user to any to silence the error, tsc checks nothing further. And if a call such as sendMail(...) loses its await and its result is never used, then as far as types go no operation is wrong, so do not count on tsc to find it; you have to review those calls yourself.

Add the await, and this is where strict earns its keep. With strictNullChecks on, tsc reports a second error: user has type User | undefined, so you may not read .email yet. Fixing that exposes a third: email may be null. The final fix narrows the type in both places:

export async function notify(id: string) {
  const user = await getUser(id);
  if (!user) {
    logger.warn({ id }, "user not found");
    return;
  }
  if (user.email === null) {
    logger.warn({ id }, "user has no email");
    return;
  }
  await sendMail(user.email);    // email is definitely a string here
}

Notice how you reached the fix. There was no guessing. Each error tsc reported was a real case in the client’s data that the old code ignored, and each early return leaves a log line that tells the client’s team why an email was not sent.

npm is the map of the repo

Before reading a line of code, open package.json. The scripts field maps each command name to the actual command to run, so npm run build and npm run test are the standard entry points for building and testing the repo. You do not need to guess which tools the client uses; they are all written down there.

Next, look at the two groups of dependencies. The npm documentation says test harnesses, transpilers and development-only tools should not go in dependencies.

They belong in devDependencies, the way you separate production requirements from dev-requirements. package-lock.json pins the exact dependency tree and is designed to be committed to the repo.

If your fix changes that file, include it in the same PR.

There is one new trap. Recent versions of Node can run .ts files directly by replacing TypeScript syntax with whitespace, and they do no type checking whatsoever.

Features that need a syntax transformation, such as enum, raise an error outright. So “Node runs it” proves nothing about type correctness. The missing await above still runs under Node without a warning; it surfaces only when tsc is invoked.

What stays behind after you leave

The order of work for the week is in the diagram at the top. The last step deserves extra emphasis: check that tsc sits in a script that CI runs before merging, and if it does not, propose adding it. Your fix helps the client this week; tsc in CI keeps blocking the same class of bug after you have moved on to another client.

Mistakes Python developers often make

The most common is using any to make the compiler stop complaining. That only erases the information you need. Next comes forgetting await and then hunting for the bug in the database layer. Then there is the habit of treating Node’s ability to run a .ts file as proof the code is correct.

On npm, do not install build tools into dependencies, and do not leave package-lock.json out of the commit. Both make the client’s production environment differ from your machine without anyone knowing.

On the career side, when reading FDE job postings, look at the description of the client stack: if it mentions Node or TypeScript, that is a skill to prepare evidence for in advance. On your CV, do not just write “TypeScript.” Write a specific line: you turned on strict in an existing codebase, the number of type errors you fixed, and adding tsc to CI.

A recruiter reading that line will see that you can deliver on a client’s stack as well as your own.

An exercise for this week: in the repo you are working on, remove the await from an async call whose result is read on the next line, then run tsc; then repeat with a call whose result is discarded. The first time tsc complains, the second time it stays silent, and that silence marks exactly where you will need to check by hand at your next client.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
8 sources
Read next on the roadmap · Stage 2: Broad engineeringText-to-SQL can run without errors and still get revenue wrongA schema cannot tell a model how finance calculates MRR, so define each metric once in a semantic layer that LLMs and reports share.