Skip to content

Conversation

@webpro
Copy link
Member

@webpro webpro commented Aug 18, 2023

When a project has declaration files (.d.ts) added through e.g. the include: [] configuration in tsconfig.json, how to get ts.resolveModuleName() take them into account?

This PR includes a fixture that has assets.d.ts:

declare module '*.html?raw';

With a module importing another:

import b from './block.html?raw';

The result with Knip is an unresolved module, since I don't know how to properly include the declaration files in the TypeScript backend. Full repro:

$ git clone -b fix/include-dts [email protected]:webpro/knip.git
$ cd knip
$ npm install
$ cd fixtures/dts/
$ npx knip
Unused files (1)
src/assets.d.ts
Unresolved imports (1)
./block.html?raw  src/index.ts

The TypeScript backend is set up mainly in the constructor of the ProjectPrincipal class using a language service and compiler host in createHosts.ts with a custom resolveModuleNames function.

In this PR I have added some code and comments to indicate where the relevant bits are.

To rephrase my question: how to properly include declaration files not explicitly included through import statements?

(By the way, the current workaround in Knip is to let this slip through and eventually sanitize the import specifiers and ignore specifiers having an extension from this list.)

@webpro webpro added the help wanted Extra attention is needed label Aug 18, 2023
@webpro
Copy link
Member Author

webpro commented Aug 23, 2023

@webpro
Copy link
Member Author

webpro commented Sep 25, 2023

@webpro webpro closed this in 11f91f9 Sep 26, 2023
@webpro
Copy link
Member Author

webpro commented Sep 26, 2023

🚀 This issue has been resolved in v2.29.0. See Release 2.29.0 for release notes.

@webpro webpro deleted the fix/include-dts branch February 12, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants