Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The inferred type of 'actions' cannot be named without a reference to '../../.yarn/__virtual__/@reduxjs-toolkit-virtual-5ff160901c/4/.yarn/berry/cache/@reduxjs-toolkit-npm-2.2.3-3fa8bcc11c-10c0.zip/node_modules/@reduxjs/toolkit/dist/entities/models'. This is likely not portable. A type annotation is necessary. #58474

Closed
chenhebing opened this issue May 8, 2024 · 4 comments

Comments

@chenhebing
Copy link

chenhebing commented May 8, 2024

🔎 Search Terms

yarn pnp or pnpm symlink, A type annotation is necessary.

image

🕗 Version & Regression Information

typescript@5, using yarn berry pnp mode, cannot reference the actions of @reduxjs/toolkit, but there is no problem using typescript@4.9.5.

⏯ Playground Link

No response

💻 Code

import { createEntityAdapter, createSlice } from '@reduxjs/toolkit';

export interface IFileNav {
  id: string
  path: string;
}

const fileNavAdapter = createEntityAdapter<IFileNav>();

const fileNavSlice = createSlice({
  name: 'file_nav',
  initialState: fileNavAdapter.getInitialState(),
  reducers: {
    add: fileNavAdapter.addMany,
    remove: fileNavAdapter.removeMany,
  },
});

export const actions = fileNavSlice.actions;

🙁 Actual behavior

The following error message appears, but the type reference can still be indexed

The inferred type of 'actions' cannot be named without a reference to '../../.yarn/__virtual__/@reduxjs-toolkit-virtual-5ff160901c/4/.yarn/berry/cache/@reduxjs-toolkit-npm-2.2.3-3fa8bcc11c-10c0.zip/node_modules/@reduxjs/toolkit/dist/entities/models'. This is likely not portable. A type annotation is necessary.

🙂 Expected behavior

The type declaration of symlink can be obtained correctly

Additional information about the issue

// .yarnrc.yml

changesetBaseRefs:
  - master
  - origin/master

checksumBehavior: update

conditions:
  USE_SRC:
    default: false

enableColors: true

enableGlobalCache: true

enableStrictSsl: false

nodeLinker: pnp

npmPublishRegistry: 'https://bnpm.byted.org/'

npmRegistryServer: 'https://bnpm.byted.org/'

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-conditions.cjs
    spec: 'https://raw.githubusercontent.com/nicolo-ribaudo/yarn-plugin-conditions/main/bundles/%40yarnpkg/plugin-conditions.js'

pnpEnableEsmLoader: true

unsafeHttpWhitelist:
  - bnpm.byted.org

yarnPath: .yarn/releases/yarn-4.2.1.cjs

// tsconfig.json

{
  "compilerOptions": {
    // Type Checking
    "strict": true,
    "strictPropertyInitialization": false,
    "exactOptionalPropertyTypes": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true,
    // Modules
    "allowArbitraryExtensions": true,
    "baseUrl": ".",
    "module": "ES2022",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    // Emit
    "declaration": true,
    "declarationMap": true,
    "noEmitOnError": true,
    "outDir": "build",
    "removeComments": true,
    "sourceMap": true,
    "stripInternal": true,
    // JavaScript Support
    "allowJs": true,
    // Interop Constraints
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    // Language and Environment
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "jsx": "preserve",
    "target": "ES2022",
    // Projects
    "composite": true,
    "incremental": true,
    // Output Formatting
    "skipLibCheck": true
  },
  "include": ["client", "server", "protocol"],
  "exclude": ["node_modules", "build"],
  "ts-node": {
    "transpileOnly": true,
    "esm": true,
    "swc": true,
    "require": ["tsconfig-paths/register"],
    "compilerOptions": {
      "module": "NodeNext",
      "moduleResolution": "NodeNext"
    }
  }
}
@jakebailey
Copy link
Member

I'd suggest using nightly since #58176 likely fixed this, but you're also using PnP which requires patching TypeScript so is very unlikely to work on nightly.

@chenhebing
Copy link
Author

chenhebing commented May 9, 2024

I'd suggest using nightly since #58176 likely fixed this, but you're also using PnP which requires patching TypeScript so is very unlikely to work on nightly.

Thanks Reply. I just tried it. In typescript@4.9.5, changing moduleResolution to node16 also had the same problem. Looks like it may be related to nodenext exports.

@chenhebing
Copy link
Author

It doesn't seem to be a PnP problem. I changed nodeLinker to node-modules mode, but still got the error.

image

I tried to follow the error message and modified the type export declaration of @reduxjs/toolkit and found that the problem was fixed.

image

@chenhebing
Copy link
Author

It seems to be a problem with @reduxjs/toolkit and has nothing to do with typescript. I will close this issue first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants