microsoft / microsoft/TypeScript

Idea: Can declaration emit synthesize type aliases?

Open
#44,045 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Performance Experimentation Needed Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Object types can be very large and in (e.g.) a react project that makes heavy use of type inference, it's not uncommon to have to refer to a type that is either not imported or is simply anonymous (e.g. a props type). When these appear in multiple places in a declaration file, they tend to expand it considerably. Perhaps we could just synthesize type aliases for them?

  • We'd have to be careful not to change the exported API shape
  • We could use a heuristic to skip the work for small types (e.g. < 20 characters)
  • Even if we didn't wait until the second use of a type to decide to extract it, we'd be adding ~4 tokens per type (type id = and id at the use site)

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 proposes synthesizing type aliases during declaration emit for repeated large anonymous object types. No files, tests, or entry points are named; first map the declaration-emit implementation and evaluate the stated size heuristic. Done means reducing declaration-file expansion without changing the exported API shape.

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
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.