Comments (6)
It looks like this hasn't worked since --module preserve
was added.
@andrewbranch in createExternalHelpersImportDeclarationIfNeeded
we always return an ESM import
-style declaration, even though we always use tslib's CommonJS exports. Would you expect under --module preserve
that we continue to inject import ... from "tslib"
, or that we emit it as a require
call?
If we go with require
, I can modify createExternalHelpersImportDeclarationIfNeeded
to return an ImportEqualsDeclaration
and have the es module transformer handle the downleveling to require
. If we stick with import
then I'll need to modify createExternalHelpersImportDeclarationIfNeeded
to treat Preserve
like it does ESNext
.
from typescript.
Hmm, I guess I would expect an ImportEqualsDeclaration if the file extension is .cts
, ImportDeclaration otherwise (this should be reflected by program.getImpliedNodeFormatForEmit
in that module mode).
even though we always use tslib's CommonJS exports
I would also expect module resolution to work correctly once the synthetic import has the correct syntaxβi.e., if we generate an ESM import, module resolution in --module preserve --moduleResolution bundler
should set the import
condition, because it can see that the emitted syntax will be an import. Vice versa if the synthetic import is an ImportEqualsDeclaration
.
from typescript.
getImpliedNodeFormatForEmit
doesn't detect "type": "commonjs"
or "type": "module"
for a .ts
file when using preserve
because getImpliedNodeFormatForFileWorker
never hits the branch that populates sourceFile.packageJsonCache
.
from typescript.
I'm mostly tempted to make it always import=
under preserve
because it is consistent and the transformer for preserve
already properly handles import=
. Using the implied node format means that a .ts
file in a package with "type": "commonjs"
ends up with invalid import syntax.
from typescript.
Though, I suppose preserve
really isn't meant to work with "type": "commonjs"
since we don't have a CJS-only variant for export class
et al.
from typescript.
getImpliedNodeFormatForEmit
doesn't detect"type": "commonjs"
or"type": "module"
for a.ts
file when usingpreserve
becausegetImpliedNodeFormatForFileWorker
never hits the branch that populatessourceFile.packageJsonCache
.
Yeah, this is expected behavior. After community feedback, we decided that .mts
and .cts
should be universal signals of module format, but package.json "type"
should only be used inside node_modules or --module nodenext
.
from typescript.
Related Issues (20)
- tsserver requires `npm` to be installed on `neovim` trough `mason` HOT 2
- RangeError: Maximum call stack size exceeded when calling `getJsDocTags` on getter of class that implements itself
- Class constructors that early return another object still require fields to be assigned HOT 2
- [NewErrors] 5.7.0-dev.20240922 vs 5.6.2 HOT 6
- [ServerErrors][JavaScript] 5.7.0-dev.20240922 vs 5.6.2 HOT 3
- [ServerErrors][TypeScript] 5.7.0-dev.20240922 vs 5.6.2 HOT 7
- IsolatedDeclarations: emitted declarations inconsistent between `transpileDeclaration` API and TypeScript Playground HOT 1
- Inconsistent typechecking with require() in JS and TS HOT 5
- TypeScript fails to narrow union of native Error types HOT 5
- Typed JSON imports HOT 3
- Proposal: Expand `inferFromTypeArguments()` candidates to include heritage elements HOT 1
- `ReadonlySet` and `ReadonlyMap` are lacking `Symbol.toStringTag`
- Wrong type is generated by typescript HOT 6
- wrong type ordering generated by `tsc`? HOT 9
- Typing error when adding an element to a generic Map not catched by Typescript HOT 6
- Type of outer variable inside functions is not affected by narrowing in outer scope HOT 1
- Function expression or method is not inferable when we have mapped type with a conditional type HOT 2
- Predicates break arbitrarily when intersected with some types. (Probably when the predicate is generic).
- Specialized error message when too new a lib is provided
- Remove Map<any, any> constructor overload HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.