<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 = {...};
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
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.
<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 codeFixing
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:
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: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 commentTracking
[ ]
src/vs/base/common/event.ts
[ ]
src/vs/base/common/objects.ts
[ ]
src/vs/base/common/uri.ts
@jrieken[ ]
src/vs/base/common/worker/simpleWorker.ts
[ ]
src/vs/base/parts/ipc/common/ipc.ts
[ ]
src/vs/base/parts/ipc/node/ipc.cp.ts
[ ]
src/vs/editor/browser/services/webWorker.ts
[ ]
src/vs/editor/browser/widget/diffEditor/utils.ts
[x]
src/vs/editor/contrib/hover/browser/markerHoverParticipant.ts
needs help from @bpasero[x]
src/vs/editor/standalone/browser/quickInput/standaloneQuickInputService.ts
@TylerLeonhardt[x]
src/vs/nls.ts
@TylerLeonhardt[ ]
src/vs/platform/environment/node/argv.ts
[ ]
src/vs/platform/issue/electron-main/issueMainService.ts
@justschen[ ]
src/vs/platform/list/browser/listService.ts
[x]
src/vs/platform/product/common/product.ts
[x]
src/vs/platform/quickinput/browser/quickInputController.ts
@TylerLeonhardt[x]
src/vs/platform/quickinput/browser/quickInputService.ts
@TylerLeonhardt[ ]
src/vs/platform/quickinput/browser/quickPickPin.ts
@TylerLeonhardt[ ]
src/vs/platform/request/node/requestService.ts
@chrmarti[ ]
src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts
[ ]
src/vs/platform/update/common/update.ts
@joaomoreno[x]
src/vs/platform/utilityProcess/electron-main/utilityProcess.ts
[ ]
src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
@jrieken[x]
src/vs/workbench/api/browser/mainThreadNotebook.ts
@rebornix[ ]
src/vs/workbench/api/browser/mainThreadTask.ts
[ ]
src/vs/workbench/api/common/extHost.api.impl.ts
@jrieken[x]
src/vs/workbench/api/common/extHostDebugService.ts
@connor4312[ ]
src/vs/workbench/api/common/extHostTypeConverters.ts
@jrieken[ ]
src/vs/workbench/browser/actions/quickAccessActions.ts
@TylerLeonhardt[ ]
src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts
@jrieken[ ]
src/vs/workbench/contrib/accessibility/browser/accessibleView.ts
[ ]
src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane.ts
@jrieken[x]
src/vs/workbench/contrib/chat/browser/actions/chatActions.ts
@roblourens[x]
src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts
@roblourens[x]
src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.ts
@roblourens[x]
src/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables.ts
[x]
src/vs/workbench/contrib/chat/common/chatModel.ts
@roblourens[ ]
src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts
@alexr00[ ]
src/vs/workbench/contrib/files/browser/explorerService.ts
@lramos15[x]
src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts
@rebornix[ ]
src/vs/workbench/contrib/preferences/browser/keybindingsEditor.ts
@ulugbekna[ ]
src/vs/workbench/contrib/preferences/browser/settingsTree.ts
@rzhao271[ ]
src/vs/workbench/contrib/webview/browser/themeing.ts
@mjbvz[ ]
src/vs/workbench/electron-sandbox/actions/windowActions.ts
[ ]
src/vs/workbench/services/extensions/common/extensionsRegistry.ts
@alexdima[ ]
src/vs/workbench/services/preferences/browser/keybindingsEditorModel.ts
@ulugbekna[ ]
src/vs/workbench/services/preferences/common/preferencesModels.ts
@rzhao271[x]
src/vs/workbench/test/browser/workbenchTestServices.ts
@mjbvz