microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.04k stars 12.49k forks source link

The inferred type of X cannot be named without a reference to @types/qs #59172

Closed ALagoni97 closed 4 months ago

ALagoni97 commented 4 months ago

🔎 Search Terms

typescript inheritance issue symlink issue pnpm issue

🕗 Version & Regression Information

After using pnpm workspace this issue occured. On another project I am working on it is working fine. I just can't seem to find the right reason this is happening...

⏯ Playground Link

No response

💻 Code

export interface ApiContext {
    database: typeof database
    auth: {
        userId: string
        email: string
    } | null
}

export function simpleWithContext(
    fn: (req: Request, res: Response, context: ApiContext, next: NextFunction) => void
): RequestHandler {
    return async (req, res, next) => {
        try {
            return fn(
                req,
                res,
                {
                    auth: null,
                    database,
                },
                next
            )
        } catch (error: any) {
            return res.status(500).json({ error: error.message })
        }
    }
}

export const login = simpleWithContext(async (req, res, { database }, next) => {
    if (!req.body.email || !req.body.accessToken) {
        return res.status(400).send()
    }
    return res.status(200).send()
})

My API package.json:

    "dependencies": {
        "@apollo/server": "^4.9.3",
        "@graphql-tools/load-files": "^7.0.0",
        "@graphql-tools/merge": "^9.0.0",
        "@project-to-be-named/library": "workspace:^",
        "dotenv": "^16.3.1",
        "express": "^4.18.2",
        "graphql": "^16.8.0",
        "js-yaml": "^4.1.0",
        "jsonwebtoken": "^9.0.2",
        "nats": "^2.18.0",
        "octokit": "^3.1.2",
        "uuid": "^9.0.1",
        "valon-args": "^3.0.2"
    },
    "devDependencies": {
        "@graphql-codegen/add": "^5.0.0",
        "@graphql-codegen/cli": "^5.0.0",
        "@graphql-codegen/typescript-resolvers": "^4.0.1",
        "@types/cors": "^2.8.14",
        "@types/express": "^4.17.17",
        "@types/js-yaml": "^4.0.9",
        "@types/jsonwebtoken": "^9.0.3",
        "@types/node": "^20.4.8",
        "@types/uuid": "^9.0.4",
        "concurrently": "^8.2.1",
        "cors": "^2.8.5",
        "nodemon": "^3.0.1",
        "tsc-alias": "^1.8.7",
        "tsc-watch": "^6.0.4"
    }

My root project package.json:

"devDependencies": {
        "@types/node": "^20.4.8",
        "@typescript-eslint/eslint-plugin": "^7.15.0",
        "@typescript-eslint/parser": "^7.15.0",
        "eslint": "^8.46.0",
        "eslint-config-prettier": "^8.10.0",
        "eslint-plugin-prettier": "^5.0.0",
        "eslint-plugin-react": "^7.33.1",
        "prettier": "^3.0.1",
        "prisma": "^5.16.1",
        "ts-node": "^10.9.1",
        "typescript": "^5.5.3"
    },
    "dependencies": {
        "@prisma/client": "^5.16.1"
    }

🙁 Actual behavior

I am getting: The inferred type of 'login' cannot be named without a reference to '.pnpm/@types+express-serve-static-core@4.19.5/node_modules/@types/express-serve-static-core'. This is likely not portable. A type annotation is necessary.ts(2742)

🙂 Expected behavior

Just infer the type correctly... As I have in other projects.

Additional information about the issue

No response

RyanCavanaugh commented 4 months ago

See https://github.com/microsoft/TypeScript/wiki/FAQ#the-inferred-type-of-x-cannot-be-named-without-a-reference-to-y-this-is-likely-not-portable-a-type-annotation-is-necessary . express-serve-static-core is not in your dependencies list so this an expected error

ALagoni97 commented 4 months ago

See https://github.com/microsoft/TypeScript/wiki/FAQ#the-inferred-type-of-x-cannot-be-named-without-a-reference-to-y-this-is-likely-not-portable-a-type-annotation-is-necessary . express-serve-static-core is not in your dependencies list so this an expected error

Hmm okay. Thanks for reply. 😊