Skip to content

fix(devframe): fix scoped shared state types on TypeScript 7 - #509

Open
SaKaNa-Y wants to merge 2 commits into
devframes:mainfrom
SaKaNa-Y:fix/scoped-shared-state-ts7
Open

SaKaNa-Y wants to merge 2 commits into
devframes:mainfrom
SaKaNa-Y:fix/scoped-shared-state-ts7

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #508

Summary

Vite's package build reports TS2536 when TypeScript 7 checks the scoped sharedState declaration in devframe@1.4.0. The client entry has the same error. TypeScript cannot use the constrained type parameter to index the scoped state map.

Use the map's keys directly to look up the state type. Keep the string requirement on the argument. A namespace registered with a template string index signature can have numeric keys in keyof, but the runtime expects a string.

- <T extends keyof ScopedSharedStates<NS> & string>(key: T, ...)
+ <T extends keyof ScopedSharedStates<NS>>(key: T & string, ...)

Evidence

  • Vite's package build reported two TS2536 errors with the original package. On the same Vite revision, the bundle build, declaration build and TypeScript 7.0.2 declaration check passed with the updated package.
  • Strict Node and client consumers passed on TypeScript 6.0.3 and 7.0.2. Fixed keys infer the registered state type. In a namespace with a string index signature, both entry points infer the state type for dynamic strings and reject numbers. The new regression test failed on both calls before the argument constraint was added and passed afterward.

Merge Danger

Door: Two-way. Reverting restores the TS7 declaration error.

Blast Radius: Types. All 87 emitted JavaScript files were byte-identical when built from the base and updated source in the same directory.

Use the keys of the remapped state registry directly for the Node and client overloads. The registry already produces string keys. TypeScript 7 rejects the extra intersection when checking the published indexed access types.
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/509?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-24 08:20 UTC
🔗 head 58cd0fc
🤖 automated by pulls.review

{
  "headSha": "58cd0fc9b4a1c85da0c8f89065c490de1ea45538",
  "result": {
    "overallSummary": "Fixes a TypeScript 7 regression (TS2536) in devframe's scoped `sharedState` RPC method by restructuring the generic constraint so the key type is intersected with `string` on the parameter rather than on the type parameter itself. Behavior and emitted JS are unchanged; only `.d.ts` output differs, backed by a new type-level regression test and updated snapshots.",
    "groups": [
      {
        "key": "type-fix",
        "label": "Scoped shared state type fix",
        "summary": "Rewrites the `sharedState` overload generic constraint from `keyof ScopedSharedStates<NS> & string` to `keyof ScopedSharedStates<NS>` with `T & string` on the parameter, avoiding a TS2536 error under TypeScript 7 while still rejecting non-string keys at the call site.",
        "category": "api",
        "filePaths": [
          "packages/devframe/src/client/scope.ts",
          "packages/devframe/src/types/scope.ts"
        ],
        "critical": true
      },
      {
        "key": "tests",
        "label": "Tests and snapshots",
        "summary": "Adds a regression type test covering both scoped RPC entry points and both key styles (fixed and pattern), and updates the declaration snapshots to match the new overload signature.",
        "category": "tests",
        "filePaths": [
          "packages/devframe/test/scoped-shared-state.test-d.ts",
          "tests/__snapshots__/tsnapi/devframe/client.snapshot.d.ts",
          "tests/__snapshots__/tsnapi/devframe/index.snapshot.d.ts",
          "tests/__snapshots__/tsnapi/devframe/types.snapshot.d.ts"
        ],
        "fileNotes": [
          {
            "path": "packages/devframe/test/scoped-shared-state.test-d.ts",
            "text": "New `test-d.ts` verifies that numeric/symbol keys are rejected and that string keys still correctly infer the registered state type, including for namespaces with a template-string index signature."
          }
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-24T08:20:44.889Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

Keep the type parameter directly constrained by the scoped map so TypeScript 7 can index it. Require a string at the call site because a namespace with a string index signature also admits numeric keys in keyof.
@SaKaNa-Y
SaKaNa-Y marked this pull request as ready for review November 24, 2026 08:21
@SaKaNa-Y
SaKaNa-Y requested review from antfu and antfubot November 24, 2026 08:42

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

type error with TS7

1 participant