GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Migrate the TypeScript Project to Use Modules · Issue #35210 · microsoft/TypeScript

Migrate the TypeScript Project to Use Modules #35210

New issue
Copy link
New issue
Copy link
Closed
#51387
Closed
Migrate the TypeScript Project to Use Modules#35210
#51387
Copy link
Assignees
weswighamjakebailey
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issueInfrastructureIssue relates to TypeScript team infrastructureIssue relates to TypeScript team infrastructureSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
TypeScript 5.0.0

Description

@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)
opened on Nov 19, 2019
Issue body actions

Follow-up from #34899

Today, TypeScript is authored in a relatively outdated style that uses what are called "namespaces" (formerly "internal modules"). This used to have some advantages in being able to globally access the compiler in the browser, but nowadays bundlers make this possible without exposing internal authoring details.

Benefits of Modules

Authoring with namespaces has several disadvantages today, and moving to using ES module syntax per file would likely solve those issues. Here are some of the advantages to moving to modules.

Dog-fooding

Using namespaces separates our team from the way that the community authors code. We have to learn about bugs related to module resolution from external bug reports rather than hitting them ourselves on the team. That means we can't dog-food our product the same as most modern users.

We would also hit some of the challenges module users hit with external tooling (more on this later) but this is a good thing! It will help us build the appropriate empathy to improve the situation for users.

Leaner package size with share-able bundles

TypeScript ships at least 5 different JavaScript files that are meant for different purposes - but because of the nature of namespaces, the contents of every core file is duplicated in each output file - basically, think of this as us shipping 5 virtually identical .exes because of their dependencies statically linked rather than being split into .dlls. So as a result, you end up with checker.ts's contents included 5 times in every install of typescript.

Ideally, tsc.js and typescript.js could share a majority of the code generated from src/compiler.

As an end result, we would fix #27891

Faster builds and editing

Every keystroke involves re-checking the entire program, which involves merging every global namespace's symbol tables. Not clear how long this takes in practice, but you wouldn't need to wait for that per-keystroke when editing checker.ts.

Slightly more tree-shakeable

If you're only using TypeScript's parser, you shouldn't have to pay for the checker too. Would be nice to enable API consumers like this.


Challenges

Not stopping the world

We cannot stop the team from authoring code - ideally, nobody is touching the tops of most files, so this shouldn't be a huge problem.

Have break off part of utilities.ts into privateUtilities.ts

Because stripInternal does't work on an entire file level. On the other hand, that's really handy because you don't need to use stripInternal, you just never export from that module

.d.ts bundling

We'd presumably leverage something like API Extractor. This would be new infrastructure work, and it would have to integrate into our test suite (since we already do .d.ts baselining for our API.

Death by 1000 imports

Not clear whether this is really a problem or just annoying, but people keep bringing it up.

Reacted by Gonçalo Fernandes, Bruce Pascoe, Troy Gerwien, Kitson Kelly, Wenlu Wang, Titian Cernicova-Dragomir, Rob Palmer, Sindre Sorhus, Josh Ghoulberg 👻, Aly Ahmed and 12 more
Reacted by Josh Ghoulberg 👻, Anurag Hazra, lin72h, Andrea Cappuccio, Salvatore Previti and Yukai Huang
Reacted by AnyhowStep, Ben Lichtman, Bruce Pascoe, Wenlu Wang, Nathan Fenner, Anurag Hazra, lin72h, Andrea Cappuccio, Braden Napier, Dmytro Tiapukhin and 1 more
Reacted by Yves M.

Activity

  1. Daniel Rosenwasser (DanielRosenwasser)
    added
    SuggestionAn idea for TypeScriptAn idea for TypeScript
    CommittedThe team has roadmapped this issueThe team has roadmapped this issue
    InfrastructureIssue relates to TypeScript team infrastructureIssue relates to TypeScript team infrastructure
    on Nov 19, 2019
  2. sandersn commented on Nov 19, 2019

    @sandersn
    Nathan Shively-Sanders (sandersn)
    on Nov 19, 2019
    Member
    More actions

    Reminder: 1000 is 1/36 of the total lines of checker.ts. That's fewer imports per source line than most Javascript I've written.

    Reacted by AnyhowStep, Andrew Branch, Wenlu Wang, ExE Boss, Paul Draper, Thomas Mclennan, Brian, Dmytro Tiapukhin and 王一赫
    Reacted by Ryan Cavanaugh, Wenlu Wang, Josh Ghoulberg 👻, ExE Boss, Igor Oleinikov, Oliver Bell, Jesper Engberg, Amit Beckenstein, Brian, strager and 1 more
  3. fatcerberus commented on Nov 20, 2019

    @fatcerberus
    Bruce Pascoe (fatcerberus)
    on Nov 20, 2019
    More actions

    I don’t care so much about the tree-shaking, I just want to be able to consume TS using import instead of require(). You can’t use require() at all in Node in ESM files to my knowledge; I allow this in miniSphere but you then have to use an absolute path:
    https://github.com/fatcerberus/spectacles-i/blob/master/buildtime/ts-tool.js#L35

    I want the above to be an relative path but I can’t because in my engine, using import would try to load it as ESM—and fail.

  4. kitsonk commented on Nov 20, 2019

    @kitsonk
    Kitson Kelly (kitsonk)
    on Nov 20, 2019
    Contributor
    More actions

    This would resolve #32949 as well so 👍 🎉

  5. kitsonk commented on Nov 20, 2019

    @kitsonk
    Kitson Kelly (kitsonk)
    on Nov 20, 2019
    Contributor
    More actions

    Also, .d.ts generation would be a good dog-fooding exercise of some of what we have to deal with in creating libraries based on TypeScript, so what you likely solve there would benefit all of us.

  6. fatcerberus commented on Nov 20, 2019

    @fatcerberus
    Bruce Pascoe (fatcerberus)
    on Nov 20, 2019
    More actions

    Reminder: 1000 is 1/36 of the total lines of checker.ts.

    To be fair, though, checker.ts is absolutely massive. It's the only time I've ever encountered a source file in a project so large that GitHub totally refuses to display it. 😆

    (To be clear: I don't really buy the death-by-1000-imports argument. As long as a program is well-structured, this doesn't become an issue in my experience.)

  7. kitsonk commented on Nov 20, 2019

    @kitsonk
    Kitson Kelly (kitsonk)
    on Nov 20, 2019
    Contributor
    More actions

    (To be clear: I don't really buy the death-by-1000-imports argument. As long as a program is well-structured, this doesn't become an issue in my experience.)

    And if you use a type self development language and environment, management of the imports is pretty easy... 😆

  8. Daniel Rosenwasser (DanielRosenwasser)
    assigned
    Wesley Wigham (weswigham)
    on Nov 20, 2019
  9. Daniel Rosenwasser (DanielRosenwasser)
    added this to the Backlog milestone on Nov 20, 2019
  10. NoelAbrahams commented on Jan 1, 2020

    @NoelAbrahams
    Noel Abrahams (NoelAbrahams)
    on Jan 1, 2020
    More actions

    Daniel Rosenwasser (@DanielRosenwasser) You've missed out the biggest con: Moving from organising code in virtual hierarchies (ie namespaces) to a system based on the physical file system.

  11. kitsonk commented on Jan 1, 2020

    @kitsonk
    Kitson Kelly (kitsonk)
    on Jan 1, 2020
    Contributor
    More actions

    How is that a con?

    Reacted by Daniel Rosenwasser, Stephen Wade and NDH
    Reacted by Daniel Rosenwasser and kollster
  12. Jake Bailey (jakebailey)
    self-assigned this
    on Feb 9, 2022
  13. pauldraper commented on Apr 25, 2022

    @pauldraper
    Paul Draper (pauldraper)
    on Apr 25, 2022
    More actions

    How is that a con?

    I assume because the organization of the API has to conform the organization of development (source files).

    But this is the reason barrel modules exist.

  14. Daniel Rosenwasser (DanielRosenwasser)
    modified the milestones: Backlog, TypeScript 5.0.0 on Oct 31, 2022
  15. TypeScript Bot (typescript-bot)
    added
    Fix AvailableA PR has been opened for this issueA PR has been opened for this issue
    on Nov 2, 2022
  16. jakebailey commented on Nov 2, 2022

    @jakebailey
    Jake Bailey (jakebailey)
    on Nov 2, 2022
    Member
    More actions

    For those following this issue, the module conversion PR has been posted: #51387

    Reacted by Evan Wallace, Max, lin72h, Paul Draper and Alejandro
    Reacted by Yves M.
  17. Jake Bailey (jakebailey)
    closed this as completedin #51387on Nov 7, 2022
  18. Jake Bailey (jakebailey)
    added a commit that references this issue on Nov 7, 2022

    Merge pull request #51387 from jakebailey/typeformer-2

    1d96eb4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jakebailey
    Jake Bailey (jakebailey)
  • @weswigham
    Wesley Wigham (weswigham)

Labels

CommittedThe team has roadmapped this issueThe team has roadmapped this issueFix AvailableA PR has been opened for this issueA PR has been opened for this issueInfrastructureIssue relates to TypeScript team infrastructureIssue relates to TypeScript team infrastructureSuggestionAn idea for TypeScriptAn idea for TypeScript

Type

No type

Projects

No projects

    Milestone

    • TypeScript 5.0.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.