microsoft / microsoft/TypeScript
Typecheck multiple module formats at once
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
(The other side of #15833)
Search Terms
typecheck multiple module formats
Suggestion
For projects that compile to multiple output formats - e.g. different module outputs - it would be useful to have typechecking able to emit errors for multiple formats at once.
The reason that duplicate typechecking is needed is that typechecking is slightly different based on the module - e.g. for commonjs / AMD, export = and import foo = require(...) are both legal, whereas in ESNext they are not; ESNext has import.meta and in some cases, top level await, that AMD/Commonjs don't support. So no single module target has the strictest typechecking.
The benefits are:
- save CPU time
- no need for running typecheck multiple times and get most errors duplicated between them
On it's own, I'm not sure it'll make a ton of sense - e.g. in compilerOptions the module field could take an array of modules, or we could use a new field for this; though together with emit for multiple module types (#15833) we could keep the invariant that tsc typechecks with the same module(s) that it emits.
Use Cases
If I compile my code to both AMD and ESNext, typechecking only as AMD or only as ESNext, does not guarantee my code is valid for the other module format - an export = will fail ESNext typechecking, whereas an import.meta will fail AMD typechecking; so there's no single strictest typecheck mode; as is to guarantee correctness, I need to typecheck against all the module formats we emit, and then any type errors in e.g. function bodies would get repeated in both typechecks. Deduping these errors would be the main benefit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the related issue #15833 and the existing compilerOptions.module handling. Define how multiple module formats would be configured and typechecked together, including duplicate-error handling; done means the proposal supports the stated AMD, CommonJS, and ESNext cases without requiring separate typecheck runs.
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
- 25/100