8000 TSC fails to locate .d.ts files when using "paths" remapping + ".js" extension · Issue #41642 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
TSC fails to locate .d.ts files when using "paths" remapping + ".js" extension #41642
@Nonanick

Description

@Nonanick

TypeScript Version: 4.0.5

Search Terms:
path remapping, paths, compilerOptions, .js, resolution, declaration types, .d.ts, module resolution, could not find declaration files

Code
Mocked File system:

/ project / included / in /  file.ts  > File which shall require the ".js" file
/ project / root / of / file.js > Bundled file
/ project / root / of / file.d.ts > Bundled declarations file

in tsconfig.json:

{
  "compilerOptions": {
  ...
  "moduleResolution": "node",
  "baseUrl": ".",
  "paths": {
      "/*": [
        "./*"
      ]
    }
  },
}

When running "tsc --traceResolution" the compiler successfully finds the .js file, resolving the module name, but does not lookup for .d.ts file:

======== Resolving module '/root/of/file.js' from '/project/included/in/file.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/project', using this value to resolve non-relative module name '/root/of/file.js'.
'paths' option is specified, looking for a pattern to match module name '/root/of/file.js'.
Module name '/root/of/file.js', matched pattern '/*'.
Trying substitution './*', candidate module location: './root/of/file.js'.
File '/project/root/of/file.js' exist - use it as a name resolution result.
======== Module name '/root/of/file.js' was successfully resolved to '/project/root/of/file.js'. ========

As seen in the log messages TSC is able to resolve the .js file but does not load the "file.d.ts" standing right next to it!

Expected behavior:
When specifying a path ending with ".js", required for browser module resolution, Typescript should be able to locate the corresponding declaration file with a matching name on the same directory!
Removing the slash from the beginning, "root/of/file.js", makes Typescript correctly identify the .d.ts file, but browsers complain of non-relative paths...

Actual behavior:
Compiler / Typescript stops the resolution on the ".js" file failing to import type definitions therefore outputting the following error:
"Could not find a declaration file for module '/root/of/file.js'. '/project/root/of/file.js' implicitly has an 'any' type."

Playground Link:
Cannot be replicated in the playground!

Related Issues:
Could not find any open issue regarding the same subject!

Metadata

Metadata

Assignees

Labels

DuplicateAn existing issue was already createdFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0