microsoft / microsoft/TypeScript

Cannot use ".d.ts" file on non-relative import with `rootDirs` and `baseUrl`

Open
#54,749 0 comments 0 reactions 1 assignee View on GitHub

@weswigham is already working on this.

Since Jun 23, 2023.

Needs Investigation Rescheduled
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

baseUrl rootDirs non-relative module .d.ts

🕗 Version & Regression Information
  • This is the behavior in every version I tried : 5.1.3 and 4.9.5.
⏯ Playground Link

Playground link with relevant code

💻 Code
// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "./src",
    "rootDirs": [".", "generated"],
  }
}
// src/index.ts
import stylesA from "css/a.module.scss" // 👎 Cannot find module 'css/a.module.scss' or its corresponding type declarations.ts(2307)
import stylesB from "./css/b.module.scss" // 👍

console.log(stylesA, stylesB)
// src/css/a.module.scss
.a {
    color: red;
}

// src/css/b.module.scss
.b {
    color: red;
}
// generated/src/css/a.module.scss.d.ts
export type Styles = {
  'a': string;
};

declare const styles: Styles;

export default styles;

// generated/src/css/b.module.scss.d.ts
export type Styles = {
  'b': string;
};

declare const styles: Styles;

export default styles;
🙁 Actual behavior

On first import in index.ts, the ".d.ts" file is not found: "Cannot find module 'css/a.module.scss' or its corresponding type declarations.ts(2307)"
On the second one, the ".d.ts" file is found and types are displayed correctly.

🙂 Expected behavior

Whenever it's a non-relative import (thanks to the baseUrl option) or a relative import, it should find the ".d.ts" file because of the rootDirs settings.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.