microsoft / microsoft/TypeScript

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

Aperta
#54,749 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 23/6/2023.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.