Skip to content

Key type error — Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ParamsSlotMap' - discriminated union narrowing failing in generated code #4032

@hallvors

Description

@hallvors

Follow-up to issue #3862, very similar symptom but according to Pullfrog a different cause:

Hm.. tried to regenerate code with 0.98.1 now, but unfortunately I still get this:

myproject@0.0.0 build
nx build

nx run admin:build:production

▲ Next.js 16.2.6 (Turbopack)

  Running TypeScript  .Failed to type check.

../../libs/data-access-client/src/lib/generated/core/params.gen.ts:147:13
Type error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ParamsSlotMap'.
  No index signature with a parameter of type 'string' was found on type 'ParamsSlotMap'.

  145 |             (params[field.in] as Record<string, unknown>)[name] = value;
  146 |           } else {
147 |             params[field.map] = value;
      |             ^
  148 |           }
  149 |         } else {
  150 |           const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
Next.js build worker exited with code: 1 and signal: null
Build process exited due to code 1  

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target build for project admin (3s)

   ✖  1/1 failed

TS config is a bit convoluted here, set up by Nx.

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "noImplicitAny": true,
    "strict": true,
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "target": "es2016",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "importHelpers": true,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": "."
  },
  "exclude": ["node_modules", "tmp"]
}

In the part of the monorepo where the generated code lives, three files:
tsconfig.json

  "extends": "../../tsconfig.base.json",
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.lib.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

tsconfig.lib.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "node16",
    "moduleResolution": "node16",
    "lib": ["ES2020", "DOM"],
    "target": "es2016",
    "outDir": "../../dist/out-tsc",
    "declaration": true,
    "types": ["node"]
  },
  "exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
  "include": ["**/*.ts"]
}

tsconfig.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "node16",
    "moduleResolution": "node16",
    "lib": ["ES2020", "DOM"],
    "target": "es2016",
    "types": ["jest", "node"]
  },
  "include": [
    "**/*.test.ts",
    "**/*.spec.ts",
    "**/*.test.tsx",
    "**/*.spec.tsx",
    "**/*.test.js",
    "**/*.spec.js",
    "**/*.test.jsx",
    "**/*.spec.jsx",
    "**/*.d.ts",
    "jest.config.ts"
  ]
}

Originally posted by @hallvors in #3862

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions