Skip to content

Commit e35e3b4

Browse files
authored
Merge pull request microsoft#269777 from mjbvz/dev/mjbvz/obedient-cow
Fix all any casts in TS extension
2 parents c2ae070 + 21337a4 commit e35e3b4

File tree

9 files changed

+58
-45
lines changed

9 files changed

+58
-45
lines changed

extensions/typescript-language-features/src/commands/tsserverRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function isCancellationToken(value: any): value is vscode.CancellationToken {
1414
return value && typeof value.isCancellationRequested === 'boolean' && typeof value.onCancellationRequested === 'function';
1515
}
1616

17-
interface RequestArgs {
17+
export interface RequestArgs {
1818
readonly file?: unknown;
1919
readonly $traceId?: unknown;
2020
}

extensions/typescript-language-features/src/languageFeatures/completions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
777777
dotAccessorContext = { range, text };
778778
}
779779
}
780-
// eslint-disable-next-line local/code-no-any-casts
781-
const isIncomplete = !!response.body.isIncomplete || (response.metadata as any)?.isIncomplete;
780+
const isIncomplete = !!response.body.isIncomplete || !!(response.metadata as Record<string, unknown>)?.isIncomplete;
782781
const entries = response.body.entries;
783782
const metadata = response.metadata;
784783
const defaultCommitCharacters = Object.freeze(response.body.defaultCommitCharacters);

extensions/typescript-language-features/src/languageFeatures/signatureHelp.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ function toTsTriggerReason(context: vscode.SignatureHelpContext): Proto.Signatur
105105
case vscode.SignatureHelpTriggerKind.TriggerCharacter:
106106
if (context.triggerCharacter) {
107107
if (context.isRetrigger) {
108-
// eslint-disable-next-line local/code-no-any-casts
109-
return { kind: 'retrigger', triggerCharacter: context.triggerCharacter as any };
108+
return { kind: 'retrigger', triggerCharacter: context.triggerCharacter as Proto.SignatureHelpRetriggerCharacter };
110109
} else {
111-
// eslint-disable-next-line local/code-no-any-casts
112-
return { kind: 'characterTyped', triggerCharacter: context.triggerCharacter as any };
110+
return { kind: 'characterTyped', triggerCharacter: context.triggerCharacter as Proto.SignatureHelpTriggerCharacter };
113111
}
114112
} else {
115113
return { kind: 'invoked' };

extensions/typescript-language-features/src/tsServer/bufferSyncSupport.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class SyncedBuffer {
168168
) { }
169169

170170
public open(): void {
171-
const args: Proto.OpenRequestArgs = {
171+
const args: Proto.OpenRequestArgs & { plugins?: string[] } = {
172172
file: this.filepath,
173173
fileContent: this.document.getText(),
174174
projectRootPath: this.getProjectRootPath(this.document.uri),
@@ -183,8 +183,7 @@ class SyncedBuffer {
183183
.filter(x => x.languages.indexOf(this.document.languageId) >= 0);
184184

185185
if (tsPluginsForDocument.length) {
186-
// eslint-disable-next-line local/code-no-any-casts
187-
(args as any).plugins = tsPluginsForDocument.map(plugin => plugin.name);
186+
args.plugins = tsPluginsForDocument.map(plugin => plugin.name);
188187
}
189188

190189
this.synchronizer.open(this.resource, args);

extensions/typescript-language-features/src/tsServer/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Cancellation } from '@vscode/sync-api-common/lib/common/messageCancellation';
77
import * as vscode from 'vscode';
8+
import { RequestArgs } from '../commands/tsserverRequests';
89
import { TypeScriptServiceConfiguration } from '../configuration/configuration';
910
import { TelemetryReporter } from '../logging/telemetry';
1011
import Tracer from '../logging/tracer';
@@ -15,11 +16,11 @@ import { ServerResponse, ServerType, TypeScriptRequests } from '../typescriptSer
1516
import { Disposable } from '../utils/dispose';
1617
import { isWebAndHasSharedArrayBuffers } from '../utils/platform';
1718
import { OngoingRequestCanceller } from './cancellation';
19+
import { NodeVersionManager } from './nodeManager';
1820
import type * as Proto from './protocol/protocol';
1921
import { EventName } from './protocol/protocol.const';
2022
import { TypeScriptVersionManager } from './versionManager';
2123
import { TypeScriptVersion } from './versionProvider';
22-
import { NodeVersionManager } from './nodeManager';
2324

2425
export enum ExecutionTarget {
2526
Semantic,
@@ -283,8 +284,8 @@ export class SingleTsServer extends Disposable implements ITypeScriptServer {
283284
}
284285

285286
this._requestQueue.enqueue(requestInfo);
286-
// eslint-disable-next-line local/code-no-any-casts
287-
if (args && typeof (args as any).$traceId === 'string') {
287+
const traceId = (args as RequestArgs).$traceId;
288+
if (args && typeof traceId === 'string') {
288289
const queueLength = this._requestQueue.length - 1;
289290
const pendingResponses = this._pendingResponses.size;
290291
const data: { command: string; queueLength: number; pendingResponses: number; queuedCommands?: string[]; pendingCommands?: string[] } = {
@@ -299,8 +300,7 @@ export class SingleTsServer extends Disposable implements ITypeScriptServer {
299300
data.pendingCommands = this.getPendingCommands();
300301
}
301302

302-
// eslint-disable-next-line local/code-no-any-casts
303-
this._telemetryReporter.logTraceEvent('TSServer.enqueueRequest', (args as any).$traceId, JSON.stringify(data));
303+
this._telemetryReporter.logTraceEvent('TSServer.enqueueRequest', traceId, JSON.stringify(data));
304304
}
305305
this.sendNextRequests();
306306

extensions/typescript-language-features/src/utils/platform.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export function isWeb(): boolean {
1010
}
1111

1212
export function isWebAndHasSharedArrayBuffers(): boolean {
13-
// eslint-disable-next-line local/code-no-any-casts
14-
return isWeb() && (globalThis as any)['crossOriginIsolated'];
13+
return isWeb() && !!(globalThis as Record<string, unknown>)['crossOriginIsolated'];
1514
}
1615

1716
export function supportsReadableByteStreams(): boolean {

extensions/typescript-language-features/web/src/serverHost.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ import { PathMapper, looksLikeNodeModules, mapUri } from './pathMapper';
1313
import { findArgument, hasArgument } from './util/args';
1414
import { URI } from 'vscode-uri';
1515

16+
type TsModule = typeof ts;
17+
18+
interface TsInternals extends TsModule {
19+
combinePaths(path: string, ...paths: (string | undefined)[]): string;
20+
21+
matchFiles(
22+
path: string,
23+
extensions: readonly string[] | undefined,
24+
excludes: readonly string[] | undefined,
25+
includes: readonly string[] | undefined,
26+
useCaseSensitiveFileNames: boolean,
27+
currentDirectory: string,
28+
depth: number | undefined,
29+
getFileSystemEntries: (path: string) => { files: readonly string[]; directories: readonly string[] },
30+
realpath: (path: string) => string
31+
): string[];
32+
33+
generateDjb2Hash(data: string): string;
34+
35+
memoize: <T>(callback: () => T) => () => T;
36+
ensureTrailingDirectorySeparator: (path: string) => string;
37+
getDirectoryPath: (path: string) => string;
38+
directorySeparator: string;
39+
}
40+
1641
type ServerHostWithImport = ts.server.ServerHost & { importPlugin(root: string, moduleName: string): Promise<ts.server.ModuleImportResult> };
1742

1843
function createServerHost(
@@ -29,33 +54,16 @@ function createServerHost(
2954
const fs = apiClient?.vscode.workspace.fileSystem;
3055

3156
// Internals
32-
// eslint-disable-next-line local/code-no-any-casts
33-
const combinePaths: (path: string, ...paths: (string | undefined)[]) => string = (ts as any).combinePaths;
57+
const combinePaths = (ts as TsInternals).combinePaths;
3458
const byteOrderMarkIndicator = '\uFEFF';
35-
const matchFiles: (
36-
path: string,
37-
extensions: readonly string[] | undefined,
38-
excludes: readonly string[] | undefined,
39-
includes: readonly string[] | undefined,
40-
useCaseSensitiveFileNames: boolean,
41-
currentDirectory: string,
42-
depth: number | undefined,
43-
getFileSystemEntries: (path: string) => { files: readonly string[]; directories: readonly string[] },
44-
realpath: (path: string) => string
45-
// eslint-disable-next-line local/code-no-any-casts
46-
) => string[] = (ts as any).matchFiles;
47-
// eslint-disable-next-line local/code-no-any-casts
48-
const generateDjb2Hash = (ts as any).generateDjb2Hash;
59+
const matchFiles = (ts as TsInternals).matchFiles;
60+
const generateDjb2Hash = (ts as TsInternals).generateDjb2Hash;
4961

5062
// Legacy web
51-
// eslint-disable-next-line local/code-no-any-casts
52-
const memoize: <T>(callback: () => T) => () => T = (ts as any).memoize;
53-
// eslint-disable-next-line local/code-no-any-casts
54-
const ensureTrailingDirectorySeparator: (path: string) => string = (ts as any).ensureTrailingDirectorySeparator;
55-
// eslint-disable-next-line local/code-no-any-casts
56-
const getDirectoryPath: (path: string) => string = (ts as any).getDirectoryPath;
57-
// eslint-disable-next-line local/code-no-any-casts
58-
const directorySeparator: string = (ts as any).directorySeparator;
63+
const memoize = (ts as TsInternals).memoize;
64+
const ensureTrailingDirectorySeparator = (ts as TsInternals).ensureTrailingDirectorySeparator;
65+
const getDirectoryPath = (ts as TsInternals).getDirectoryPath;
66+
const directorySeparator = (ts as TsInternals).directorySeparator;
5967
const executingFilePath = findArgument(args, '--executingFilePath') || location + '';
6068
const getExecutingDirectoryPath = memoize(() => memoize(() => ensureTrailingDirectorySeparator(getDirectoryPath(executingFilePath))));
6169
const getWebPath = (path: string) => path.startsWith(directorySeparator) ? path.replace(directorySeparator, getExecutingDirectoryPath()) : undefined;

extensions/typescript-language-features/web/src/webServer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ import { createSys } from './serverHost';
1313
import { findArgument, findArgumentStringArray, hasArgument, parseServerMode } from './util/args';
1414
import { StartSessionOptions, startWorkerSession } from './workerSession';
1515

16-
// eslint-disable-next-line local/code-no-any-casts
17-
const setSys: (s: ts.System) => void = (ts as any).setSys;
16+
type TsModule = typeof ts;
17+
18+
interface TsInternals extends TsModule {
19+
setSys(sys: ts.System): void;
20+
}
21+
22+
const setSys: (s: ts.System) => void = (ts as TsInternals).setSys;
1823

1924
async function initializeSession(
2025
args: readonly string[],

extensions/typescript-language-features/web/src/workerSession.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export interface StartSessionOptions {
2222
readonly disableAutomaticTypingAcquisition: boolean;
2323
}
2424

25+
type ServerModule = typeof ts.server;
26+
27+
interface TsServerInternals extends ServerModule {
28+
indent(str: string): string;
29+
}
30+
2531
export function startWorkerSession(
2632
ts: typeof import('typescript/lib/tsserverlibrary'),
2733
host: ts.server.ServerHost,
@@ -31,8 +37,7 @@ export function startWorkerSession(
3137
pathMapper: PathMapper,
3238
logger: Logger,
3339
): void {
34-
// eslint-disable-next-line local/code-no-any-casts
35-
const indent: (str: string) => string = (ts as any).server.indent;
40+
const indent = (ts.server as TsServerInternals).indent;
3641

3742
const worker = new class WorkerSession extends ts.server.Session<{}> {
3843

0 commit comments

Comments
 (0)