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

Fix unsafe type assertions on object literals #211878

Open
19 of 48 tasks
mjbvz opened this issue May 2, 2024 · 3 comments · Fixed by #212790
Open
19 of 48 tasks

Fix unsafe type assertions on object literals #211878

mjbvz opened this issue May 2, 2024 · 3 comments · Fixed by #212790
Assignees
Labels
debt Code quality issues
Milestone

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented May 2, 2024

<T>{ ... } style type assertions are unsafe as they can hide some common typing errors such as missing properties on the object. This has caused errors for me multiple times now, so I think it would be good to make a pass through the code

Fixing

I've added a new eslint rule for this called local/code-no-dangerous-type-assertions. You can turn it on in .eslintrc.json

In most cases, we should prefer using proper typings such as:

const x = <T>{...};

// Becomes --->

const x: T = {...};
arr.map(x => <T>{ ... })

// Becomes --->

arr.map((x): T => ({ ... }));

If you want to make sure an object fulfills a certain type, prefer using the satisfies operator instead which will enforce the type without actually changing its shape:

const x = <T>{...};

// Becomes --->

const x = {...} satisfies T;

Note that this rule still allows <any> casts for now. You can also suppress this rule in the few cases where you need to workaround it using an eslint comment


Tracking

  • src/vs/base/common/event.ts

    • 1271:21
  • src/vs/base/common/objects.ts

    • 261:17
  • src/vs/base/common/uri.ts @jrieken

    • 476
  • src/vs/base/common/worker/simpleWorker.ts

    • 411:17
  • src/vs/base/parts/ipc/common/ipc.ts

    • 429:36
    • 432:37
    • 440:37
    • 461:68
    • 487:37
    • 556:10
    • 848:10
    • 997:9
    • 1013:9
  • src/vs/base/parts/ipc/node/ipc.cp.ts

    • 105:10
  • src/vs/editor/browser/services/webWorker.ts

    • 110:27
  • src/vs/editor/browser/widget/diffEditor/utils.ts

    • 192:17
  • src/vs/editor/contrib/hover/browser/markerHoverParticipant.ts needs help from @bpasero

    • 159:43
  • src/vs/editor/standalone/browser/quickInput/standaloneQuickInputService.ts @TylerLeonhardt

    • 116:135
  • src/vs/nls.ts @TylerLeonhardt

    • 250:15
  • src/vs/platform/environment/node/argv.ts

    • 270:13
  • src/vs/platform/issue/electron-main/issueMainService.ts @justschen

    • 413:36
  • src/vs/platform/list/browser/listService.ts

    • 1157:12
  • src/vs/platform/product/common/product.ts

    • 56:12
  • src/vs/platform/quickinput/browser/quickInputController.ts @TylerLeonhardt

    • 337:135
  • src/vs/platform/quickinput/browser/quickInputService.ts @TylerLeonhardt

    • 151:135
  • src/vs/platform/quickinput/browser/quickPickPin.ts @TylerLeonhardt

    • 60:53
  • src/vs/platform/request/node/requestService.ts @chrmarti

    • 168:13
  • src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts

    • 50:11
    • 442:33
    • 525:44
    • 784:44
  • src/vs/platform/update/common/update.ts @joaomoreno

    • 76:17
    • 77:44
    • 78:53
    • 81:15
  • src/vs/platform/utilityProcess/electron-main/utilityProcess.ts

    • 244:56
  • src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts @jrieken

    • 435:157
    • 445:167
    • 460:153
    • 562:25
  • src/vs/workbench/api/browser/mainThreadNotebook.ts @rebornix

    • 107:62
  • src/vs/workbench/api/browser/mainThreadTask.ts

    • 492:13
  • src/vs/workbench/api/common/extHost.api.impl.ts @jrieken

    • 1471:25
  • src/vs/workbench/api/common/extHostDebugService.ts @connor4312

    • 416:39
    • 886:36
    • 893:32
    • 899:41
    • 904:36
  • src/vs/workbench/api/common/extHostTypeConverters.ts @jrieken

    • 631:63
    • 640:54
    • 647:54
    • 660:62
    • 670:63
    • 791:35
    • 970:43
    • 984:38
    • 990:48
    • 997:44
    • 1010:36
    • 1015:46
    • 1021:53
    • 1031:50
    • 1602:44
  • src/vs/workbench/browser/actions/quickAccessActions.ts @TylerLeonhardt

    • 168:21
  • src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts @jrieken

    • 88:47
  • src/vs/workbench/contrib/accessibility/browser/accessibleView.ts

    • 531:45
  • src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane.ts @jrieken

    • 123:30
  • src/vs/workbench/contrib/chat/browser/actions/chatActions.ts @roblourens

    • 119:73
  • src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts @roblourens

    • 99:92
  • src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.ts @roblourens

    • 100:110
    • 114:109
  • src/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables.ts

    • 102:133
    • 166:61
  • src/vs/workbench/contrib/chat/common/chatModel.ts @roblourens

    • 657:7
  • src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts @alexr00

    • 47:53
  • src/vs/workbench/contrib/files/browser/explorerService.ts @lramos15

    • 187:111
  • src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts @rebornix

    • 145:30
    • 164:30
  • src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts @ulugbekna

    • 737:19
    • 746:19
    • 755:19
    • 764:19
    • 773:19
    • 782:19
    • 791:19
    • 800:19
    • 809:19
    • 878:19
    • 889:19
  • src/vs/workbench/contrib/preferences/browser/settingsTree.ts @rzhao271

    • 167:12
    • 182:11
    • 204:11
    • 222:10
    • 1719:31
  • src/vs/workbench/contrib/webview/browser/themeing.ts @mjbvz

    • 66:7
  • src/vs/workbench/electron-sandbox/actions/windowActions.ts

    • 260:16
  • src/vs/workbench/services/extensions/common/extensionsRegistry.ts @alexdima

    • 219:16
  • src/vs/workbench/services/preferences/browser/keybindingsEditorModel.ts @ulugbekna

    • 88:80
    • 113:72
    • 276:27
  • src/vs/workbench/services/preferences/common/preferencesModels.ts @rzhao271

    • 428:48
    • 546:22
    • 564:26
    • 837:19
    • 887:27
    • 958:26
  • src/vs/workbench/test/browser/workbenchTestServices.ts @mjbvz

    • 214:31
@mjbvz mjbvz self-assigned this May 2, 2024
@mjbvz mjbvz added the debt Code quality issues label May 2, 2024
@mjbvz mjbvz added this to the May 2024 milestone May 2, 2024
mjbvz added a commit to mjbvz/vscode that referenced this issue May 2, 2024
alexr00 added a commit that referenced this issue May 3, 2024
@alexr00
Copy link
Member

alexr00 commented May 3, 2024

I think I got all mine ✅

alexr00 added a commit that referenced this issue May 3, 2024
Tyriar added a commit that referenced this issue May 3, 2024
meganrogge added a commit that referenced this issue May 3, 2024
@connor4312
Copy link
Member

I got rid of mine, but I had to add a new cast via a mapValues function in common/objects.ts -- still better to keep the unsafeness hidden inside well-defined functions.

meganrogge added a commit that referenced this issue May 7, 2024
mjbvz added a commit to mjbvz/vscode that referenced this issue May 13, 2024
mjbvz added a commit that referenced this issue May 13, 2024
hediet added a commit that referenced this issue May 14, 2024
hediet added a commit that referenced this issue May 14, 2024
SimonSiefke pushed a commit to SimonSiefke/vscode that referenced this issue May 14, 2024
SimonSiefke pushed a commit to SimonSiefke/vscode that referenced this issue May 14, 2024
@rebornix rebornix removed their assignment Jul 29, 2024
@bpasero bpasero removed their assignment Aug 2, 2024
TylerLeonhardt added a commit that referenced this issue Aug 2, 2024
bpasero added a commit that referenced this issue Aug 3, 2024
@mjbvz mjbvz modified the milestones: August 2024, September 2024 Aug 23, 2024
@roblourens roblourens removed their assignment Sep 3, 2024
@connor4312 connor4312 removed their assignment Sep 6, 2024
@connor4312 connor4312 self-assigned this Sep 6, 2024
@mjbvz mjbvz modified the milestones: September 2024, October 2024 Sep 20, 2024
@mjbvz
Copy link
Collaborator Author

mjbvz commented Sep 20, 2024

Getting close! Thanks for all the help. Let's plan on finishing this up in the October debt week

@chrmarti chrmarti removed their assignment Sep 27, 2024
rzhao271 added a commit that referenced this issue Sep 27, 2024
@rzhao271 rzhao271 removed their assignment Sep 27, 2024
@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Sep 27, 2024
@ulugbekna ulugbekna reopened this Sep 30, 2024
@vs-code-engineering vs-code-engineering bot removed the unreleased Patch has not yet been released in VS Code Insiders label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Code quality issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.