Comments (8)
https://stackblitz.com/~/github.com/Noriller/ts-issue-58214
I hope this one helps.
In the test.d.ts
with the current typescript@next
and same jsconfig
(its a legacy project, using mostly jsdocs, but with the problem in a d.ts
file)
If changing ts version with:
npm i -D [email protected]
then both work
from typescript.
We need a complete repro here; the package.json of @some/package
, its contents, the importing package, and the tsconfig for the importing file all matter
from typescript.
This bisects to #57896. @andrewbranch
(I'm not an expert, but it seems strange that you'd need an extension when the d.ts file is effectively CJS, importing another CJS file, but importing via a JS file is already funky.)
from typescript.
Guessing I accidentally made ImportTypes look like an ESM-mode source location, when they were previously kept CJS-mode for backward compatibility reasons. Will take a look. Thanks!
from typescript.
Your jsconfig.json is invalid:
Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'
module
is defaulting to es2015 because of target
, which is causing everything to resolve under ESM rules (since everything will emit as ESM). Iād argue this is probably more logically consistent than what we used to do, where the module resolution implementation made a lot more assumptions about module format and emit.
I guess we could consider making --moduleResolution node16
imply --module node16
instead of issuing an error, but I think we did the error on purpose so that people would notice we were making a breaking change when we started requiring these options be used together in #54567.
from typescript.
That works for the import, but adding "module = node16" breaks for .js
files "exporting" jsdoc
types.
I've updated the example with that case (link again)
When a .js
file don't import/export anything (in this one case it's still using module.exports
) then the declared types can be used globally as if they were declared in a d.ts
file.
Using "module = commonjs" apparently fixes the problem I had earlier while keeping other uses working, but it still gives an error in the jsconfig
file.
I also had other projects that did have modules and that we do have types declared in a separate file.
BTW, about the error, since package.json also has a "module" option, maybe too much, but adding a "in this config file" to that type of error might make it clearer.
As for the case of exporting jsdoc
types for global use, I'm not sure what should be the intended behavior.
from typescript.
You can set "moduleDetection": "legacy"
from typescript.
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
from typescript.
Related Issues (20)
- isolatedDeclarations should not have warning for functions that have no return statements HOT 4
- Trivia ownership documentation seems to be incorrect
- `--isolatedDeclarations` allows generator functions HOT 1
- Allow `--noCheck` on the CLI with top-level `--build`
- Union in template literal simplifying unexpectedly HOT 5
- Default import from an ESM package into a CommonJS project with esModuleInterop is faulty HOT 3
- Watch cannot handle large amount of file changes HOT 1
- generator next type should be inferred as union (instead of intersection) of yields' types OR just unknown
- Elementwise elaboration fails to be found for properties mixed with incompatible index signatures using intersections
- Error when accessing properties on `globalThis` with the same name of a global variable
- [NewErrors] 5.5.0-dev.20240428 vs 5.4.5 HOT 49
- Private class properties prevent `Readonly` type inference HOT 2
- [ServerErrors][TypeScript] 5.5.0-dev.20240428 HOT 12
- [ServerErrors][JavaScript] 5.5.0-dev.20240428 HOT 9
- Strange runtime caching bug involving `as const` and `const T` generic HOT 1
- When relatively importing a `.d.ts` file in a declaration file, TypeScript loads a `.ts` file instead HOT 7
- Calling decorators with @ loses type safety with function as argument HOT 2
- Include error maps in the typescript libraries for web apis to give developers easy access to potential thrown exceptions HOT 5
- jsdoc @type does not resolve a type
- Removing `node_modules`, running `npm ci` leaves diagnostics behind in ts and tsconfig files
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.