microsoft / microsoft/TypeScript

Typescript 5.6.3 throwing error "The inferred type of X cannot be named without a reference to Y. This is likely not portable. A type annotation is necessary."

Aperta
#60,214 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

🔎 Search Terms

"inferred type" "portable" "type annotation is necessary" "cannot be named without a reference to"

🕗 Version & Regression Information
  • This changed between versions 5.5.4 and 5.6.3
⏯ Playground Link

https://github.com/livingforjesus/typescript-inferred-type-bug-repro

💻 Code
// Your code here
import { makeStyles } from "tss-react/mui";

// this doesn't work
const PPCTableStyle = makeStyles()({});

export default PPCTableStyle;
🙁 Actual behavior

We have been using typescript v5.5.4 in our project and I wanted to upgrade to v5.6.3(latest). On attempt, the code sample above had a typescript error "The inferred type of 'PPCTableStyle' cannot be named without a reference to '../node_modules/tss-react/types'. This is likely not portable. A type annotation is necessary."

This has been working previously but since 5.5.4->5.6.*, it stopped working and threw this error.

🙂 Expected behavior

I'm expecting this code snippet to work since it has been previously working on earlier versions

Additional information about the issue

We are working in a monorepo and use pnpm version manager. However I was able to repro via yarn in a non-monorepo environment.

Below is the tsconfig

{
  "compilerOptions": {
    "allowJs": false,
    "composite": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "incremental": true,
    "inlineSources": true,
    "isolatedModules": true,
    "noImplicitOverride": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "tsBuildInfoFile": "./dist/.tsbuildinfo",
    "outDir": "./dist",
    "resolveJsonModule": true,
    "rootDir": ".",
    "noEmit": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": false,
    "target": "ES6",
    "jsx": "preserve",
    "lib": ["DOM", "ESNext"]
  },
  "exclude": [
    "./dist",
    "./node_modules",
    "./out",
    "./.next",
    "./dist",
    "./node_modules"
  ],
  "include": ["./next-env.d.ts", "./**/*.ts", "./**/*.tsx"]
}

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.

Direzione di ricerca

Inizia dal repository di riproduzione collegato e confronta il comportamento dell’esempio con TypeScript 5.5.4 e 5.6.3, utilizzando la configurazione di tsconfig e delle dipendenze fornita. Traccia la gestione delle dichiarazioni o dei tipi inferiti per makeStyles e identifica perché il tipo generato fa riferimento a tss-react/types; il lavoro è considerato completato quando l’esempio compila senza richiedere un’annotazione manuale, mantenendo al contempo la copertura della regressione segnalata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.