microsoft / microsoft/TypeScript

`./*.d.ts` required in `exports` to avoid `Cannot be named without a reference to... not portable...`

Abierto
#60,913 12 comentarios 3 reacciones 1 asignado Ver en GitHub

@weswigham ya está trabajando en esto.

Desde el 9/10/2025.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

🔎 Search Terms

The inferred type of '...' cannot be named without a reference to... This is likely not portable. A type annotation is necessary.

🕗 Version & Regression Information

Between 5.3 to 5.7 (latest)

⏯ Playground Link

No response

💻 Code
TSconfig of importing project
{
  "compilerOptions": {
    "outDir": "./lib",
    "rootDir": "./src",
    "tsBuildInfoFile": "./lib/.tsbuildinfo",

    "target": "ESNext",
    "module":"ESNext",
    "moduleResolution":"bundler",

    "composite": true,
    "declarationMap": true,
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "noErrorTruncation": true,
    "verbatimModuleSyntax": true,

    "emitDeclarationOnly": true,
    "skipLibCheck": true,

    "allowJs": true,

    
  },
  "include": ["src/**/*"]
}
Package.json of project BEING IMPORTED
{

  "type": "module",
  "files": [
    "lib/**/*",
    "src/**/*"
  ],
  "exports": {
    "./lib/*.d.ts": "./lib/*.d.ts",
    ".": {
      "types":"./lib/index.d.ts",
      "import":"./lib/index.js"
    }
  },
}

🙁 Actual behavior

If you do not include "./lib/*.d.ts": "./lib/*.d.ts" in the package.json of the imported project, you will receive the ...likely not portable... error.

However, in none of the documentations and searches I've seen was this written as a requirement. As a result, I assume it's a bug.

The problem with the above solution is that it exposes the .d.ts files, which causes intellisense import suggestions to suggest two imports (one from the proper path, and one from the .d.ts path).

Note:

  1. The import is a direct dependency, not a transitive dependency.
  2. Using main:./lib/index.js instead of exports:... also removes the error.
🙂 Expected behavior

Should not need to explicitly export all types

Additional information about the issue

No response

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.