microsoft / microsoft/TypeScript

Typescript fails to resolve module when type definitions are placed outside the root path (with typesVersions)

Abierto
#43,133 1 comentario 2 reacciones 1 asignado Ver en GitHub

@rbuckton ya está trabajando en esto.

Desde el 9/3/2021.

Needs Investigation Rescheduled
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

Bug Report

If you have a project with embedded type definitions that are not in root path. i.e.: src/index.d.ts and src/ts4.1/index.d.ts, TypeScript fails to resolve this module when using the following approach:

  "types": "./src/index.d.ts",
  "typesVersions": {
    ">=4.1": {
      "*": [
        "src/ts4.1/*"
      ]
    }
  },

src/i18n/config.ts:4:34 - error TS2307: Cannot find module 'react-i18next' or its corresponding type declarations.

import { useTranslation } from 'react-i18next';

It works, if we replace * to index.d.ts, like this:

  "types": "./src/index.d.ts",
  "typesVersions": {
    ">=4.1": {
      "*": [
        "src/ts4.1/index.d.ts"
      ]
    }
  },

However, when we replace it with the actual file (src/ts4.1/index.d.ts), VS Code sometimes imports the module incorrectly, i.e.:

import { useTranslation } from 'react-i18next/*';

Rather than:

import { useTranslation } from 'react-i18next';

Here you can find some context.

💻 Code

https://github.com/i18next/react-i18next/blob/master/package.json#L7

"types": "./src/index.d.ts",
"typesVersions": {
  ">=4.1": {
    "*": [
      "src/ts4.1/index.d.ts"
    ]
  }
},
🙁 Actual behavior

It fails to compile, and fails to auto-import properly.

import { useTranslation } from 'react-i18next/*';
🙂 Expected behavior

Resolve the module and import it properly.

import { useTranslation } from 'react-i18next';

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.