Skip to content

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

@jfirebaugh

Description

@jfirebaugh

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 typescript@5.9

No error.

Behavior with tsgo

express.ts:3:14 - error TS2742: The inferred type of 'handler' cannot be named without a reference to '.pnpm/@types+express-serve-static-core@4.19.7/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/@types+qs@6.14.0/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions