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."

Open
#60,214 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs More Info
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 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"]
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked repro repository and compare the sample's behavior under TypeScript 5.5.4 and 5.6.3, using the provided tsconfig and dependency setup. Trace declaration or inferred-type handling for makeStyles and identify why the generated type references tss-react/types; done means the sample compiles without requiring a manual annotation while preserving the reported regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.