typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

TS2742: The inferred type of ... cannot be named...

Open jfirebaugh opened this issue 2 weeks ago • 0 comments

Another issue like #1034 that persists after the fixes there. Unlike #2276, this one reproduces only when using pnpm install.

Steps to reproduce

package.json

{
  "type": "module",
  "dependencies": {
    "@types/express": "4.17.23",
    "express": "4.21.2"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "module": "node20",
        "moduleResolution": "node16",
        "declaration": true
    }
}

express.ts

import express from "express";

export const handler = async (req: express.Request, res: express.Response) => {};

Behavior with [email protected]

No error.

Behavior with tsgo

express.ts:3:14 - error TS2742: The inferred type of 'handler' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@types/express-serve-static-core'. This is likely not portable. A type annotation is necessary.

3 export const handler = async (req: express.Request, res: express.Response) => {};
               ~~~~~~~

express.ts:3:14 - error TS2742: The inferred type of 'handler' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@types/qs'. This is likely not portable. A type annotation is necessary.

3 export const handler = async (req: express.Request, res: express.Response) => {};
               ~~~~~~~


Found 2 errors in the same file, starting at: express.ts:3

Note that these errors do not occur if you install via npm i. It appears to be the pnpm node_modules structure triggering it.

jfirebaugh avatar Dec 08 '25 20:12 jfirebaugh