microsoft / microsoft/TypeScript

Dead code typecheck elimination

Open
#54,826 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Suggestion

🔍 Search Terms

dead code typecheck elimination

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

When the include field is set, TypeScript will only typecheck the given files ... and their dependencies, and transitive dependencies. It can grow unwieldy pretty fast.

It'd be good for performances to if TS could have a skipDeadCodeTypechecks call that would cause it to skip the typecheck of all statements that aren't part of the execution tree of the files listed inside include.

📃 Motivating Example

If you were announcing this feature in a blog post, what's a short explanation that shows
a developer why this feature improves the language?

In the new TypeScript update, we're excited to introduce the skipDeadCodeTypechecks feature. This was born out of the need for a more efficient type-checking process. Previously, when setting the include field, TypeScript would typecheck all given files, their dependencies, and their transitive dependencies. This could quickly get out of hand, resulting in a typechecking process that would run over many more files than the author intended!

The skipDeadCodeTypechecks feature aims to solve this issue. Instead of typechecking every single file and their dependencies, this new feature will only typecheck the code that is actually executed when the files listed inside include are run. This means that TypeScript will skip typechecking for code that is not part of the execution tree for these files, hence "dead" code.

💻 Use Cases

We have a very large repository we're trying to split into reference workspaces. But until we get there, we'd like to selectively pick the folders to typecheck. We do that with the include field, but it's still very slow (30s to typecheck what's supposed to be a relatively small part of the application).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Begin by mapping how include files and their transitive dependencies are typechecked, then define what counts as the execution tree and how skipping dead code should preserve expected diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.