Skip to content

@lwc/state Typescript definitions no longer typecheck updating functions #3600

Description

@simonfcodes

Summary

Previously, I was able to use my own typescript definitions to define the shape of returned state from defineState function - now, the typescript definitions shipping with the CLI force my updating functions to be of type (...args: unknown[]) => void - whereas I was previously able to enforce type checking at the call site of an updating function.

Steps To Reproduce

Example repository, with my type definition file, and two example LWCs with comments.

  1. Implement a new Typescript-enabled SFDX project
  2. Define state manager using defineState function
  3. Wrap a call to setAtom inside an updating function
  4. Export the function in the return statement. Typescript will provide an error if the exported function is not typed as (args: unknown[]) => void

Expected result

Functions returned as part of defineState should be correctly typed.

Actual result

Functions returned as part of defineState need to be typed as (...args: unknown[]) => void to prevent errors.

System Information

Using zsh, macOs, most recent version of CLI.

{
  "architecture": "darwin-arm64",
  "cliVersion": "@salesforce/cli/2.142.7",
  "nodeVersion": "node-v24.3.0",
  "osVersion": "Darwin 25.4.0",
  "rootPath": "/opt/homebrew/lib/node_modules/@salesforce/cli",
  "shell": "zsh",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.2.53 (core)",
    "@oclif/plugin-commands 4.1.59 (core)",
    "@oclif/plugin-help 6.2.53 (core)",
    "@oclif/plugin-not-found 3.2.88 (core)",
    "@oclif/plugin-plugins 5.4.80 (core)",
    "@oclif/plugin-search 1.2.52 (core)",
    "@oclif/plugin-update 4.7.54 (core)",
    "@oclif/plugin-version 2.2.50 (core)",
    "@oclif/plugin-warn-if-update-available 3.1.68 (core)",
    "@oclif/plugin-which 3.2.58 (core)",
    "@salesforce/cli 2.142.7 (core)",
    "agent 1.43.0 (core)",
    "apex 3.9.38 (core)",
    "api 1.3.43 (core)",
    "auth 4.4.5 (core)",
    "code-analyzer 5.8.0 (user) published 196 days ago (Mon Dec 29 2025) (latest is 5.14.0)",
    "data 4.0.110 (core)",
    "deploy-retrieve 3.24.54 (core)",
    "env 3.0.33 (user) published 687 days ago (Sun Aug 25 2024) (latest is 3.0.37)",
    "info 3.4.144 (core)",
    "lightning-dev 5.1.4 (user) published 184 days ago (Fri Jan 09 2026) (latest is 6.2.17)",
    "limits 3.3.96 (core)",
    "marketplace 1.3.35 (core)",
    "org 5.11.12 (core)",
    "packaging 2.30.1 (user) published 12 days ago (Tue Jun 30 2026)",
    "schema 3.3.122 (core)",
    "settings 2.4.89 (core)",
    "signups 2.6.56 (user) published 219 days ago (Sat Dec 06 2025) (latest is 2.6.78)",
    "sobject 1.4.117 (core)",
    "telemetry 3.8.27 (core)",
    "templates 56.18.12 (core)",
    "trust 3.8.26 (core)",
    "user 3.10.4 (core)",
    "@salesforce/sfdx-plugin-lwc-test 1.2.1 (user) published 646 days ago (Fri Oct 04 2024)",
    "sf-git-merge-driver 1.9.1 (user) published 13 days ago (Tue Jun 30 2026)",
    "sfdmu 5.8.0 (user) published 9 days ago (Fri Jul 03 2026)",
    "sfdx-git-delta 6.45.1 (user) published 17 days ago (Fri Jun 26 2026)",
    "sfdx-hardis 7.20.0 (user) published 1 days ago (Sun Jul 12 2026)"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    owned by another teamThe Salesforce CLI team does not own this work but will pass on the information to the correct team.validatedVersion information for this issue has been validated

    Type

    No type

    Fields

    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