-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Add support for @types declaration packages #163
Comments
Good feature! Do you want to ignore all the @types packages? Or only the ones on use? |
Ideally, it would be great to recognise the ones that are used, but if that doesn't prove possible it would be great to have an option that just ignores all @types scoped packaged. |
As a workaround, I'm currently using the following command to ignore all @types scoped packages: |
In a typescript project, 2 way in source code, that's simple to parse: ///<reference types="node"/>
import React from 'react';
import someThing from '@scoped/package'; // <- "@types/scoped__package" another in for each tsconfig found in project:
("typeRoots" and "types" is sub field of "compilerOptions") |
BTW, |
Oh, When I start to write some code, I found that, the first 2 ways is also affected by tsconfig.json. |
@GongT thanks for the research, that does make it seem quite complex to properly detect Instead of trying to analyze it ourselves, I wonder if there might be some way to extract this information from the typescript compiler? I haven't done a lot of research, but some documentation is here. |
I have not look into depcheck's
here is a simple script to list all files used when compile a project: |
I've opened a PR that would fix this. If people here could chip in a review perhaps it would speed the process of getting it shipped. |
This still doesn't seem solved - i'm still getting unused warnings for DT packages. |
I've also made it to this point. Doing some major cleanup and it looks to still be an issue. |
I'm seeing an issue as well. My best guess is that the solution works for importing types directly, but does not work for the Here's a reproducible example: /// <reference types="w3c-web-usb" />
const supportsUsb = !!navigator?.usb with this, depcheck reports
however, this works successfully with no error: import type { default as foo } from 'w3c-web-usb'
const supportsUsb = !!navigator?.usb |
The point of DT types is that you import them from the non-DT package name. |
Typescript v2 is moving to support a new approach to adding typings to a project.
Type definitions will be included in packages contained within the @types scope (e.g. @types/mypackage), which can simply be installed via npm (just like other packages).
More information can be found at:
https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/
Currently any of these @types packages that are referenced in package.json, are incorrectly recognised as unused dependencies.
The text was updated successfully, but these errors were encountered: