You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Restricting --moduleResolution bundler to --module esnext
--moduleResolution bundler
Some confusion due to a footgun.
When we look at package.json's exports field, we always look at the import condition, never the require.
For example, import import "yargs"
--moduleResolution nodenext depends on the package.jsontype field for a .ts or .js file
--moduleResolution bundler just looks at the syntax, regardless of the file type. require uses the require condition, imports use the import condition.
If you're using this mode, what is your end goal? What is the "correct" output target?
Bundlers usually prefer ES modules format.
But if you use --module commonjs, the output for import "foo" will be require("foo") - and bundlers will switch their resolution strategy compared to what TypeScript actually does.
This is a footgun!
Proposal: limit this mode to --module esnext.
What about a stable ES module target apart from ESNext?
es2015 - basic module syntax
es2020 - import.meta
es2022 - top-level await
Aside: respecting __esModule markers not consistent across bundlers.
It might make sense to have a corresponding --module target for --moduleResolution bundler
But it would be bad to call it that - we have no interest in bundling.
Conclusion: limit --module to esnext for --moduleResolution bundler
Idea: consult .valueOf() to see if JS relational comparisons are valid.
Found bugs
VS Code issue with sorting URIs by last-touched time - accidentally comparing the functions that would actually update the time instead of the times themselves.
Comparison on opaque types - fine at runtime, plausible bug long term. If these were branded intead of opaque, it would work better.
Restricting
--moduleResolution bundlerto--module esnext--moduleResolution bundlerpackage.json'sexportsfield, we always look at theimportcondition, never therequire.import "yargs"--moduleResolution nodenextdepends on thepackage.jsontypefield for a.tsor.jsfile--moduleResolution bundlerjust looks at the syntax, regardless of the file type.requireuses therequirecondition,importsuse theimportcondition.--module commonjs, the output forimport "foo"will berequire("foo")- and bundlers will switch their resolution strategy compared to what TypeScript actually does.--module esnext.import.metaawait__esModulemarkers not consistent across bundlers.--moduletarget for--moduleResolution bundler--moduletoesnextfor--moduleResolution bundlerConsulting
valueOf()in Relational Comparisons#52807
Idea: consult
.valueOf()to see if JS relational comparisons are valid.Found bugs
How do you deal with this?
stringor tonumber? Not correct.any? EhhWeird to say we'd just support
valueOfbut not[Symbol.toPrimitive]Still, feels like it's an overall reasonable change.
We would like to investigate bringing it in for TypeScript 5.1.