Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Prevent TypeScript compiler from checking entire classes to save time?

The typescript build 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 I was comparing complicated classes with their subclasses. For example, one of the classes is the Objection base model (https://github.com/vincit/objection.js ), which is the base class that all my models inherit.

For example, 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 finds each model it's slow, then it caches it. It takes approximately 5 seconds for TS to compare a specific model to the base Model . Model uses types from various libraries. Here is a screenshot of the trace, it takes 5 minutes to compare each model with Model :

Is there a way to make TS skip comparing Model with itself? That is, since the User extends the Model , there is no need to check the fields it inherited.

Edit:

I reduced the time to review all 50 models from 5min to 30s. I have a model map:

 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 models. It got faster if I return the base model when T is a union of all model types:

 type TypeToModel<T extends ModelType> = ModelType extends T ? Model : ModelsMap[T]; getModel<T extends ModelType>(type: T): TypeToModel<T> {}

However, it would be nice to know if there are any tricks to make the subclass comparison faster. For example, if it is possible to disable structural typing and use nominal for subclasses.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda