Skip to content

Commit d3596df

Browse files
authoredSep 30, 2024··
More type assertion fixes (#230181)
For #211878 Also adds a few suppressions
1 parent c35d5e2 commit d3596df

File tree

9 files changed

+30
-16
lines changed

9 files changed

+30
-16
lines changed
 

‎extensions/git/src/git.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ export class Repository {
24202420
return result.stdout.trim().split('\n')
24212421
.map(line => line.trim().split('\0'))
24222422
.filter(([_, upstream]) => upstream === upstreamBranch)
2423-
.map(([ref]) => ({ name: ref, type: RefType.Head } as Branch));
2423+
.map(([ref]): Branch => ({ name: ref, type: RefType.Head }));
24242424
}
24252425

24262426
async getRefs(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]> {

‎extensions/git/src/operation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5+
/* eslint-disable local/code-no-dangerous-type-assertions */
56

67
import { LogOutputChannel } from 'vscode';
78

‎extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ interface FileConfiguration {
1919
readonly preferences: Proto.UserPreferences;
2020
}
2121

22+
interface FormattingOptions {
23+
24+
readonly tabSize: number | undefined;
25+
26+
readonly insertSpaces: boolean | undefined;
27+
}
28+
2229
function areFileConfigurationsEqual(a: FileConfiguration, b: FileConfiguration): boolean {
2330
return equals(a, b);
2431
}
@@ -51,21 +58,21 @@ export default class FileConfigurationManager extends Disposable {
5158
}
5259
}
5360

54-
private getFormattingOptions(
55-
document: vscode.TextDocument
56-
): vscode.FormattingOptions | undefined {
57-
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.fileName === document.fileName);
58-
return editor
59-
? {
60-
tabSize: editor.options.tabSize,
61-
insertSpaces: editor.options.insertSpaces
62-
} as vscode.FormattingOptions
63-
: undefined;
61+
private getFormattingOptions(document: vscode.TextDocument): FormattingOptions | undefined {
62+
const editor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === document.uri.toString());
63+
if (!editor) {
64+
return undefined;
65+
}
66+
67+
return {
68+
tabSize: typeof editor.options.tabSize === 'number' ? editor.options.tabSize : undefined,
69+
insertSpaces: typeof editor.options.insertSpaces === 'boolean' ? editor.options.insertSpaces : undefined,
70+
};
6471
}
6572

6673
public async ensureConfigurationOptions(
6774
document: vscode.TextDocument,
68-
options: vscode.FormattingOptions,
75+
options: FormattingOptions,
6976
token: vscode.CancellationToken
7077
): Promise<void> {
7178
const file = this.client.toOpenTsFilePath(document);
@@ -122,7 +129,7 @@ export default class FileConfigurationManager extends Disposable {
122129

123130
private getFileOptions(
124131
document: vscode.TextDocument,
125-
options: vscode.FormattingOptions
132+
options: FormattingOptions
126133
): FileConfiguration {
127134
return {
128135
formatOptions: this.getFormatOptions(document, options),
@@ -132,7 +139,7 @@ export default class FileConfigurationManager extends Disposable {
132139

133140
private getFormatOptions(
134141
document: vscode.TextDocument,
135-
options: vscode.FormattingOptions
142+
options: FormattingOptions
136143
): Proto.FormatCodeSettings {
137144
const config = vscode.workspace.getConfiguration(
138145
isTypeScriptDocument(document) ? 'typescript.format' : 'javascript.format',

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

+1
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ export class AsyncEmitter<T extends IWaitUntil> extends Emitter<T> {
13541354
const [listener, data] = this._asyncDeliveryQueue.shift()!;
13551355
const thenables: Promise<unknown>[] = [];
13561356

1357+
// eslint-disable-next-line local/code-no-dangerous-type-assertions
13571358
const event = <T>{
13581359
...data,
13591360
token,

‎src/vs/base/common/objects.ts

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export function createProxyObject<T extends object>(methodNames: string[], invok
258258
};
259259
};
260260

261+
// eslint-disable-next-line local/code-no-dangerous-type-assertions
261262
const result = {} as T;
262263
for (const methodName of methodNames) {
263264
(<any>result)[methodName] = createProxyMethod(methodName);

‎src/vs/base/common/uri.ts

+1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ class Uri extends URI {
473473
}
474474

475475
override toJSON(): UriComponents {
476+
// eslint-disable-next-line local/code-no-dangerous-type-assertions
476477
const res = <UriState>{
477478
$mid: MarshalledId.Uri
478479
};

‎src/vs/base/parts/ipc/node/ipc.cp.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class Client implements IChannelClient, IDisposable {
102102
getChannel<T extends IChannel>(channelName: string): T {
103103
const that = this;
104104

105+
// eslint-disable-next-line local/code-no-dangerous-type-assertions
105106
return {
106107
call<T>(command: string, arg?: any, cancellationToken?: CancellationToken): Promise<T> {
107108
return that.requestPromise<T>(channelName, command, arg, cancellationToken);

‎src/vs/platform/issue/electron-main/processMainService.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class ProcessMainService implements IProcessMainService {
328328
}
329329

330330
private createBrowserWindow<T>(position: IWindowState, ipcObjectUrl: IIPCObjectUrl<T>, options: IBrowserWindowOptions, windowKind: string): BrowserWindow {
331-
const window = new BrowserWindow({
331+
const browserWindowOptions: BrowserWindowConstructorOptions & { experimentalDarkMode: boolean } = {
332332
fullscreen: false,
333333
skipTaskbar: false,
334334
resizable: true,
@@ -351,7 +351,8 @@ export class ProcessMainService implements IProcessMainService {
351351
},
352352
alwaysOnTop: options.alwaysOnTop,
353353
experimentalDarkMode: true
354-
} as BrowserWindowConstructorOptions & { experimentalDarkMode: boolean });
354+
};
355+
const window = new BrowserWindow(browserWindowOptions);
355356

356357
window.setMenuBarVisibility(false);
357358

‎src/vs/workbench/api/common/extHost.api.impl.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
15131513
}
15141514
};
15151515

1516+
// eslint-disable-next-line local/code-no-dangerous-type-assertions
15161517
return <typeof vscode>{
15171518
version: initData.version,
15181519
// namespaces

0 commit comments

Comments
 (0)
Please sign in to comment.