microsoft / microsoft/TypeScript

"The inferred type of X cannot be named without a reference to Y" (TS2742) still happens, when working with npm link to link packages manually

Aperta
#58,914 19 commenti 7 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 18/6/2024.

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

Descrizione

🔎 Search Terms

is:issue is:open 2742

🕗 Version & Regression Information

This seems to not be a regression bug

⏯ Playground Link

https://github.com/Teascade/typescript-error-demonstration

💻 Code
// In the example provided
// https://github.com/Teascade/typescript-error-demonstration

import { extended } from '@privateprefix/lib';

// src/index.ts(4,14): error TS2742: The inferred type of 'a' cannot be named without a reference to '@privateprefix/lib/node_modules/joi'. This is likely not portable. A type annotation is necessary.
export const a = extended.object().keys();

Replacing this with

// Joi is declared, but never used ts(6133)
import { type Joi, extended } from '@privateprefix/lib';

// This works now, though
export const a = extended.object().keys();
🙁 Actual behavior

Produces src/index.ts(4,14): error TS2742: The inferred type of 'a' cannot be named without a reference to '@privateprefix/lib/node_modules/joi'. This is likely not portable. A type annotation is necessary.

🙂 Expected behavior

No error is to be expected

Additional information about the issue

In https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2066874644 it was mentioned, that this issue would now be resolved in TypeScript beta 5.5.0, but it seems to still be broken in this specific scenario

I've made a minimal repository to reroduce this issue in https://github.com/Teascade/typescript-error-demonstration

The GitHub repository has a github action in which the issue is reproduced: https://github.com/Teascade/typescript-error-demonstration/actions/runs/9568149578/job/26377636108

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.