Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
Prevent Typescript compiler from checking entire classes to save time?

Typescript compilation is taking a long time to run, so I used generateTrace from https://github.com/microsoft/TypeScript/pull/40063

It showed that most of the time was comparing complicated classes with their subclasses. E.g. one of the classes is the base Objection model (https://github.com/vincit/objection.js), which is the base class that all my models inherit.

E.g. I have code like:

class User extends Model {}

function doSomething(model: typeof Model) {}

doSomething(User);

I have ~50 models. I think the first time TS encounters each model is slow, then it caches it. It takes about 5s for TS to compare a specific model with the base Model. Model uses types from several libraries. Here's a screenshot of the trace, it takes 5min just to compare each model with Model:

enter image description here

Is there a way to get TS to skip comparing Model with itself? I.e. since User extends Model, there's no need to check the fields it inherited.

Edit:

I reduced the time to check the 50 models from 5min to 30s. I have a map of models:

type ModelType = 'user' | ...

type ModelsMap = {
  user: User,
  ...
};

getModel<T extends ModelType>(type: T): ModelsMap[T] {}

This is slow because ModelsMap[T] is a union of all the models. It became faster if I return the base model when T is an union of all the model types:

type TypeToModel<T extends ModelType> = ModelType extends T ? Model : ModelsMap[T];

getModel<T extends ModelType>(type: T): TypeToModel<T> {}

However, it would still be nice to know if there are hacks to make comparing subclass faster. E.g. if it's possible to disable structural typing and use nominal for subclasses.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I'm not sure it will be very helpful in your case, but you can dramatically speed up the process by allowing the incremental flag to your tsc command:

// package.json
"tsc": "tsc -v && tsc --noEmit --skipLibCheck --incremental",

This will create a tsconfig.tsbuildinfo file, that is actually a graph of your codebase. Typescript will then only compare the entries you have changed. The first compilation will be slow, because it will generate the graph, but afterwards, the compilation time will be cut by 3 at least.

over 4 years ago · Santiago Trujillo Report

0

Some tsc flags that can help with typescript compilation speed are skipLibCheck and incremental

If that is still not fast enough, consider using a different compiler than tsc (at least in-dev). Some examples of what you could use:

  • ts-node-dev
  • ts-node
  • swc
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!