-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue: @import type
not working
#964
Comments
Hi @louwers - thanks for bringing this up! At this time dependency-cruiser does not support annotations in comments like the ones that have been around for years (e.g. When I last looked at it (~5.5 years ago) the various parsers didn't emit them in their abstract syntax tree output in a structured fashion (i.e. text only) or didn't emit them at all (e.g. acorn, swc and the typescript-eslint parser strip all comments). That would mean I'd have to write a parser for it - or bring in another library (e.g. @ajaff/tsutils (whose author also contributed to dependency-cruiser) - or these days maybe ts-api-utils which seems to be its successor). Also, at that time typing-in-jsdoc was a niche use case as far as I could see - so I decided to put it aside and work on other things. This might be different today: a quick check on today's MS typescript compiler output learns it emits something structured for jsdoc comments in its AST + some larger projects went the jsdoc-typing-in-js route, making it less of a niche feature. ... so I'll have a look again. I can't commit to a timeline a.t.m. though. |
Ah I assumed some kind of API from TypeScript was used for parsing type dependencies.
Yes and I it looks the TypeScript team changed their stance, facilitating the jsdoc-typing-in-js approach even more going forward:
microsoft/TypeScript#27387 (comment)
Cool. Thanks for the quick reply. Very neat project! |
## Description - detects [jsdoc @import imports](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag) added in TS5.5 - adds a new `jsdoc`, `jsdoc-import-tag` dependency types - adds unit tests - dog foods the `@import` jsdoc tag - [x] feature switches it in the configuration (otherwise it would be a breaking change) - - [x] feature switch true implies `parser` set to `tsc` - [x] document it (and add caveats (TS 5.5 and up - `parser` attribute set to `tsc`) - [x] adds e2e test - 🏕️ disables the yarn berry integration test - for #reasons it now acts up on the ci (node 23 issue? Something else?), where it runs perfectly fine on local machine - something to figure out later. Future work: - also detect jsdoc-bracket-import (`/** @type {import('yadda').bla} */`) statements in other jsdoc tags - see [typescript jsdoc reference](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) for a list => likely better in a _separate PR_. ## Motivation and Context Addresses #964 ## How Has This Been Tested? - [x] green ci - [x] additional automated non-regression tests ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)
@louwers I've published [email protected] a few minutes ago - it recognizes I'll try and add support for the earlier 'bracket style' imports before releasing this with the Thanks again for the very pro-active testing & feedback in the PR! |
Thanks for implementing this, and nice to see you actually have a use for it too. 👍 |
## Description - adds recognition for the 'older' bracket style imports in jsdoc (so things like `/** @type {import('thing')} */`, `/** @typedef {import('thing')} Thing */`, `/** @param {import('thing')} pParameter blablabla */`, ...) - updates documentation to reflect that it isn't a 'future feature' anymore - 🏕️ drive-by: updates jsdoc type references in dependency-cruiser's own sources TODO - [x] Add support for more exotic ways to import (e.g. `/** @type {Partial<import('bla')>} */`, `/** @type{boolean|import('bla')|import('ble')} */`, `/** {Set<string,Partial<import('bla')>} */`, ...) - [x] Verify with [the list of jsdoc tag types typescript supports](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) there's no other corner cases that can bite us. - [x] so... we currently seem to occasionally resolve these type only imports to the real implementation. Is that an issue? > [!NOTE] > an iteration of this pull request has been published [as a beta on npmjs](https://www.npmjs.com/package/dependency-cruiser/v/16.7.0-beta-2) ## Motivation and Context - necessary to be more complete than just `@import` tags (see #964 and #965) - needs to be introduced at the same time as those to prevent a breaking change ## How Has This Been Tested? - [x] green ci - [x] additional unit tests ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)
Dependency-cruiser recognizes both the release notes: https://github.com/sverweij/dependency-cruiser/releases/tag/v16.7.0 |
This creates a dependency:
This does not:
/** @import * as t from "some-package" */
Expected Behavior
I expect a (type) dependency to be created by the second form.
This syntax was introduced in TypeScript 5.5. https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#the-jsdoc-import-tag
Current Behavior
No dependency is created (even when
tsPreCompilationDeps
is true).Possible Solution
Not sure. Could be an upstream (TypeScript) bug?
Steps to Reproduce (for bugs)
index.js
types.ts
package.json
jsconfig.json
Run TypeScript, validate it works (try changing return):
Initialize depcruise (use current directory):
Context
I am trying to understand dependencies on types.
Your Environment
The text was updated successfully, but these errors were encountered: