Skip to content

Commit f675b2b

Browse files
authored
remove some any casts that aren't needed (anymore) (microsoft#166557)
1 parent 562b3db commit f675b2b

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

src/vs/base/common/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,11 @@ export type AddFirstParameterToFunctions<Target, TargetFunctionsReturnType, Firs
224224
* i.e. AtLeastOne<MyObject>;
225225
*/
226226
export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
227+
228+
229+
/**
230+
* A type that removed readonly-less from all properties of `T`
231+
*/
232+
export type Mutable<T> = {
233+
-readonly [P in keyof T]: T[P]
234+
};

src/vs/editor/common/core/wordHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function ensureValidWordDefinition(wordDefinition?: RegExp | null): RegEx
6161
if (wordDefinition.multiline) {
6262
flags += 'm';
6363
}
64-
if ((wordDefinition as any).unicode) {
64+
if (wordDefinition.unicode) {
6565
flags += 'u';
6666
}
6767
result = new RegExp(wordDefinition.source, flags);

src/vs/platform/remote/common/remoteAuthorityResolver.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ export class RemoteAuthorityResolverError extends ErrorNoTelemetry {
9797

9898
// workaround when extending builtin objects and when compiling to ES5, see:
9999
// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
100-
if (typeof (<any>Object).setPrototypeOf === 'function') {
101-
(<any>Object).setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
102-
}
100+
Object.setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
103101
}
104102
}
105103

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ export class RemoteAuthorityResolverError extends Error {
515515

516516
// workaround when extending builtin objects and when compiling to ES5, see:
517517
// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
518-
if (typeof (<any>Object).setPrototypeOf === 'function') {
519-
(<any>Object).setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
520-
}
518+
Object.setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
521519
}
522520
}
523521

@@ -2954,9 +2952,7 @@ export class FileSystemError extends Error {
29542952

29552953
// workaround when extending builtin objects and when compiling to ES5, see:
29562954
// https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
2957-
if (typeof (<any>Object).setPrototypeOf === 'function') {
2958-
(<any>Object).setPrototypeOf(this, FileSystemError.prototype);
2959-
}
2955+
Object.setPrototypeOf(this, FileSystemError.prototype);
29602956

29612957
if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') {
29622958
// nice stack traces

src/vs/workbench/api/common/extensionHostMain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
1111
import { MainContext, MainThreadConsoleShape } from 'vs/workbench/api/common/extHost.protocol';
1212
import { IExtensionHostInitData } from 'vs/workbench/services/extensions/common/extensionHostProtocol';
1313
import { RPCProtocol } from 'vs/workbench/services/extensions/common/rpcProtocol';
14-
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
14+
import { ExtensionIdentifier, IExtensionDescription, IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';
1515
import { ILogService } from 'vs/platform/log/common/log';
1616
import { getSingletonServiceDescriptors } from 'vs/platform/instantiation/common/extensions';
1717
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
@@ -22,6 +22,7 @@ import { IExtHostRpcService, ExtHostRpcService } from 'vs/workbench/api/common/e
2222
import { IURITransformerService, URITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService';
2323
import { IExtHostExtensionService, IHostUtils } from 'vs/workbench/api/common/extHostExtensionService';
2424
import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
25+
import { Mutable } from 'vs/base/common/types';
2526

2627
export interface IExitFn {
2728
(code?: number): any;
@@ -163,11 +164,11 @@ export class ExtensionHostMain {
163164

164165
private static _transform(initData: IExtensionHostInitData, rpcProtocol: RPCProtocol): IExtensionHostInitData {
165166
initData.allExtensions.forEach((ext) => {
166-
(<any>ext).extensionLocation = URI.revive(rpcProtocol.transformIncomingURIs(ext.extensionLocation));
167+
(<Mutable<IRelaxedExtensionDescription>>ext).extensionLocation = URI.revive(rpcProtocol.transformIncomingURIs(ext.extensionLocation));
167168
const browserNlsBundleUris: { [language: string]: URI } = {};
168169
if (ext.browserNlsBundleUris) {
169170
Object.keys(ext.browserNlsBundleUris).forEach(lang => browserNlsBundleUris[lang] = URI.revive(rpcProtocol.transformIncomingURIs(ext.browserNlsBundleUris![lang])));
170-
(<any>ext).browserNlsBundleUris = browserNlsBundleUris;
171+
(<Mutable<IRelaxedExtensionDescription>>ext).browserNlsBundleUris = browserNlsBundleUris;
171172
}
172173
});
173174
initData.environment.appRoot = URI.revive(rpcProtocol.transformIncomingURIs(initData.environment.appRoot));

src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEditPane.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
3838
import { ResourceEdit } from 'vs/editor/browser/services/bulkEditService';
3939
import { ButtonBar } from 'vs/base/browser/ui/button/button';
4040
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles';
41+
import { Mutable } from 'vs/base/common/types';
4142

4243
const enum State {
4344
Data = 'data',
@@ -314,9 +315,6 @@ export class BulkEditPane extends ViewPane {
314315
}
315316

316317
private async _openElementAsEditor(e: IOpenEvent<BulkEditElement | undefined>): Promise<void> {
317-
type Mutable<T> = {
318-
-readonly [P in keyof T]: T[P]
319-
};
320318

321319
const options: Mutable<ITextEditorOptions> = { ...e.editorOptions };
322320
let fileElement: FileElement;

src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export class CommentController implements IEditorContribution {
698698
return;
699699
}
700700

701-
const matchedNewCommentThreadZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && (zoneWidget.commentThread as any).commentThreadHandle === -1 && Range.equalsRange(zoneWidget.commentThread.range, thread.range));
701+
const matchedNewCommentThreadZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && zoneWidget.commentThread.commentThreadHandle === -1 && Range.equalsRange(zoneWidget.commentThread.range, thread.range));
702702

703703
if (matchedNewCommentThreadZones.length) {
704704
matchedNewCommentThreadZones[0].update(thread);

src/vs/workbench/services/remote/common/remoteAgentEnvironmentChannel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEn
1212
import { IDiagnosticInfoOptions, IDiagnosticInfo } from 'vs/platform/diagnostics/common/diagnostics';
1313
import { ITelemetryData, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
1414
import { IExtensionHostExitInfo } from 'vs/workbench/services/remote/common/remoteAgentService';
15+
import { Mutable } from 'vs/base/common/types';
1516

1617
export interface IGetEnvironmentDataArguments {
1718
remoteAuthority: string;
@@ -118,7 +119,7 @@ export class RemoteExtensionEnvironmentChannelClient {
118119

119120
const extension = await channel.call<IExtensionDescription | null>('scanSingleExtension', args);
120121
if (extension) {
121-
(<any>extension).extensionLocation = URI.revive(extension.extensionLocation);
122+
(<Mutable<IExtensionDescription>>extension).extensionLocation = URI.revive(extension.extensionLocation);
122123
}
123124
return extension;
124125
}

src/vs/workbench/services/themes/common/plistParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ function _parse(content: string, filename: string | null, locationKeyName: strin
326326

327327
function escapeVal(str: string): string {
328328
return str.replace(/&#([0-9]+);/g, function (_: string, m0: string) {
329-
return (<any>String).fromCodePoint(parseInt(m0, 10));
329+
return String.fromCodePoint(parseInt(m0, 10));
330330
}).replace(/&#x([0-9a-f]+);/g, function (_: string, m0: string) {
331-
return (<any>String).fromCodePoint(parseInt(m0, 16));
331+
return String.fromCodePoint(parseInt(m0, 16));
332332
}).replace(/&amp;|&lt;|&gt;|&quot;|&apos;/g, function (_: string) {
333333
switch (_) {
334334
case '&amp;': return '&';

0 commit comments

Comments
 (0)