Skip to content

Commit 3c99d50

Browse files
Replace a few type assertions with annotations and satisfies. (microsoft#51685)
1 parent af1d91d commit 3c99d50

File tree

5 files changed

+68
-68
lines changed

5 files changed

+68
-68
lines changed

src/compiler/checker.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2410,10 +2410,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
24102410
if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
24112411
const firstFile = comparePaths(sourceSymbolFile.path, targetSymbolFile.path) === Comparison.LessThan ? sourceSymbolFile : targetSymbolFile;
24122412
const secondFile = firstFile === sourceSymbolFile ? targetSymbolFile : sourceSymbolFile;
2413-
const filesDuplicates = getOrUpdate(amalgamatedDuplicates, `${firstFile.path}|${secondFile.path}`, () =>
2414-
({ firstFile, secondFile, conflictingSymbols: new Map() } as DuplicateInfoForFiles));
2415-
const conflictingSymbolInfo = getOrUpdate(filesDuplicates.conflictingSymbols, symbolName, () =>
2416-
({ isBlockScoped: isEitherBlockScoped, firstFileLocations: [], secondFileLocations: [] } as DuplicateInfoForSymbol));
2413+
const filesDuplicates = getOrUpdate(amalgamatedDuplicates, `${firstFile.path}|${secondFile.path}`, (): DuplicateInfoForFiles =>
2414+
({ firstFile, secondFile, conflictingSymbols: new Map() }));
2415+
const conflictingSymbolInfo = getOrUpdate(filesDuplicates.conflictingSymbols, symbolName, (): DuplicateInfoForSymbol =>
2416+
({ isBlockScoped: isEitherBlockScoped, firstFileLocations: [], secondFileLocations: [] }));
24172417
if (!isSourcePlainJs) addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
24182418
if (!isTargetPlainJs) addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
24192419
}
@@ -5070,7 +5070,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
50705070

50715071
interface ExportCollisionTracker {
50725072
specifierText: string;
5073-
exportsWithDuplicate: ExportDeclaration[];
5073+
exportsWithDuplicate?: ExportDeclaration[];
50745074
}
50755075

50765076
type ExportCollisionTrackerTable = UnderscoreEscapedMap<ExportCollisionTracker>;
@@ -5090,7 +5090,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
50905090
if (lookupTable && exportNode) {
50915091
lookupTable.set(id, {
50925092
specifierText: getTextOfNode(exportNode.moduleSpecifier!)
5093-
} as ExportCollisionTracker);
5093+
});
50945094
}
50955095
}
50965096
else if (lookupTable && exportNode && targetSymbol && resolveSymbol(targetSymbol) !== resolveSymbol(sourceSymbol)) {

src/harness/vfsUtil.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ export class FileSystem {
876876
private _mknod(dev: number, type: typeof S_IFREG, mode: number, time?: number): FileInode;
877877
private _mknod(dev: number, type: typeof S_IFDIR, mode: number, time?: number): DirectoryInode;
878878
private _mknod(dev: number, type: typeof S_IFLNK, mode: number, time?: number): SymlinkInode;
879-
private _mknod(dev: number, type: number, mode: number, time = this.time()) {
879+
private _mknod(dev: number, type: number, mode: number, time = this.time()): Inode {
880880
return {
881881
dev,
882882
ino: ++inoCount,
@@ -886,7 +886,7 @@ export class FileSystem {
886886
ctimeMs: time,
887887
birthtimeMs: time,
888888
nlink: 0
889-
} as Inode;
889+
};
890890
}
891891

892892
private _addLink(parent: DirectoryInode | undefined, links: collections.SortedMap<string, Inode>, name: string, node: Inode, time = this.time()) {
@@ -979,7 +979,7 @@ export class FileSystem {
979979
birthtimeMs: root.birthtimeMs,
980980
nlink: root.nlink,
981981
shadowRoot: root
982-
} as Inode;
982+
};
983983

984984
if (isSymlink(root)) (shadow as SymlinkInode).symlink = root.symlink;
985985
shadows.set(shadow.ino, shadow);

src/server/editorServices.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ export class ProjectService {
26602660
this.eventHandler({
26612661
eventName: ConfigFileDiagEvent,
26622662
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile }
2663-
} as ConfigFileDiagEvent);
2663+
} satisfies ConfigFileDiagEvent);
26642664
}
26652665

26662666
private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined {

src/testRunner/parallel/host.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ export function start() {
372372
}
373373
worker.currentTasks = taskList;
374374
if (taskList.length === 1) {
375-
worker.process.send({ type: "test", payload: taskList[0] } as ParallelHostMessage); // TODO: GH#18217
375+
worker.process.send({ type: "test", payload: taskList[0] } satisfies ParallelHostMessage); // TODO: GH#18217
376376
}
377377
else {
378-
worker.process.send({ type: "batch", payload: taskList } as ParallelHostMessage); // TODO: GH#18217
378+
worker.process.send({ type: "batch", payload: taskList } satisfies ParallelHostMessage); // TODO: GH#18217
379379
}
380380
}
381381
}

src/testRunner/unittests/tsserver/cancellationToken.ts

+56-56
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ describe("unittests:: tsserver:: cancellationToken", () => {
3939
const session = createSession(host, { cancellationToken });
4040

4141
expectedRequestId = session.getNextSeq();
42-
session.executeCommandSeq({
43-
command: "open",
42+
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
43+
command: ts.server.protocol.CommandTypes.Open,
4444
arguments: { file: f1.path }
45-
} as ts.server.protocol.OpenRequest);
45+
});
4646

4747
expectedRequestId = session.getNextSeq();
48-
session.executeCommandSeq({
49-
command: "geterr",
50-
arguments: { files: [f1.path] }
51-
} as ts.server.protocol.GeterrRequest);
48+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
49+
command: ts.server.protocol.CommandTypes.Geterr,
50+
arguments: { files: [f1.path], delay: 0 }
51+
});
5252

5353
expectedRequestId = session.getNextSeq();
54-
session.executeCommandSeq({
55-
command: "occurrences",
54+
session.executeCommandSeq<ts.server.protocol.OccurrencesRequest>({
55+
command: ts.server.protocol.CommandTypes.Occurrences,
5656
arguments: { file: f1.path, line: 1, offset: 6 }
57-
} as ts.server.protocol.OccurrencesRequest);
57+
});
5858

5959
expectedRequestId = 2;
6060
host.runQueuedImmediateCallbacks();
@@ -82,15 +82,15 @@ describe("unittests:: tsserver:: cancellationToken", () => {
8282
cancellationToken
8383
});
8484
{
85-
session.executeCommandSeq({
86-
command: "open",
85+
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
86+
command: ts.server.protocol.CommandTypes.Open,
8787
arguments: { file: f1.path }
88-
} as ts.server.protocol.OpenRequest);
88+
});
8989
// send geterr for missing file
90-
session.executeCommandSeq({
91-
command: "geterr",
92-
arguments: { files: ["/a/missing"] }
93-
} as ts.server.protocol.GeterrRequest);
90+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
91+
command: ts.server.protocol.CommandTypes.Geterr,
92+
arguments: { files: ["/a/missing"], delay: 0 }
93+
});
9494
// Queued files
9595
assert.equal(host.getOutput().length, 0, "expected 0 message");
9696
host.checkTimeoutQueueLengthAndRun(1);
@@ -101,18 +101,18 @@ describe("unittests:: tsserver:: cancellationToken", () => {
101101
{
102102
const getErrId = session.getNextSeq();
103103
// send geterr for a valid file
104-
session.executeCommandSeq({
105-
command: "geterr",
106-
arguments: { files: [f1.path] }
107-
} as ts.server.protocol.GeterrRequest);
104+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
105+
command: ts.server.protocol.CommandTypes.Geterr,
106+
arguments: { files: [f1.path], delay: 0 }
107+
});
108108

109109
assert.equal(host.getOutput().length, 0, "expect 0 messages");
110110

111111
// run new request
112-
session.executeCommandSeq({
113-
command: "projectInfo",
114-
arguments: { file: f1.path }
115-
} as ts.server.protocol.ProjectInfoRequest);
112+
session.executeCommandSeq<ts.server.protocol.ProjectInfoRequest>({
113+
command: ts.server.protocol.CommandTypes.ProjectInfo,
114+
arguments: { file: f1.path, needFileNameList: false }
115+
});
116116
session.clearMessages();
117117

118118
// cancel previously issued Geterr
@@ -126,10 +126,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
126126
}
127127
{
128128
const getErrId = session.getNextSeq();
129-
session.executeCommandSeq({
130-
command: "geterr",
131-
arguments: { files: [f1.path] }
132-
} as ts.server.protocol.GeterrRequest);
129+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
130+
command: ts.server.protocol.CommandTypes.Geterr,
131+
arguments: { files: [f1.path], delay: 0 }
132+
});
133133
assert.equal(host.getOutput().length, 0, "expect 0 messages");
134134

135135
// run first step
@@ -148,10 +148,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
148148
}
149149
{
150150
const getErrId = session.getNextSeq();
151-
session.executeCommandSeq({
152-
command: "geterr",
153-
arguments: { files: [f1.path] }
154-
} as ts.server.protocol.GeterrRequest);
151+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
152+
command: ts.server.protocol.CommandTypes.Geterr,
153+
arguments: { files: [f1.path], delay: 0 }
154+
});
155155
assert.equal(host.getOutput().length, 0, "expect 0 messages");
156156

157157
// run first step
@@ -178,10 +178,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
178178
}
179179
{
180180
const getErr1 = session.getNextSeq();
181-
session.executeCommandSeq({
182-
command: "geterr",
183-
arguments: { files: [f1.path] }
184-
} as ts.server.protocol.GeterrRequest);
181+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
182+
command: ts.server.protocol.CommandTypes.Geterr,
183+
arguments: { files: [f1.path], delay: 0 }
184+
});
185185
assert.equal(host.getOutput().length, 0, "expect 0 messages");
186186
// run first step
187187
host.runQueuedTimeoutCallbacks();
@@ -190,10 +190,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
190190
assert.equal(e1.event, "syntaxDiag");
191191
session.clearMessages();
192192

193-
session.executeCommandSeq({
194-
command: "geterr",
195-
arguments: { files: [f1.path] }
196-
} as ts.server.protocol.GeterrRequest);
193+
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
194+
command: ts.server.protocol.CommandTypes.Geterr,
195+
arguments: { files: [f1.path], delay: 0 }
196+
});
197197
// make sure that getErr1 is completed
198198
verifyRequestCompleted(getErr1, 0);
199199
}
@@ -230,34 +230,34 @@ describe("unittests:: tsserver:: cancellationToken", () => {
230230
throttleWaitMilliseconds: 0
231231
});
232232
{
233-
session.executeCommandSeq({
234-
command: "open",
233+
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
234+
command: ts.server.protocol.CommandTypes.Open,
235235
arguments: { file: f1.path }
236-
} as ts.server.protocol.OpenRequest);
236+
});
237237

238238
// send navbar request (normal priority)
239-
session.executeCommandSeq({
240-
command: "navbar",
239+
session.executeCommandSeq<ts.server.protocol.NavBarRequest>({
240+
command: ts.server.protocol.CommandTypes.NavBar,
241241
arguments: { file: f1.path }
242-
} as ts.server.protocol.NavBarRequest);
242+
});
243243

244244
// ensure the nav bar request can be canceled
245-
verifyExecuteCommandSeqIsCancellable({
246-
command: "navbar",
245+
verifyExecuteCommandSeqIsCancellable<ts.server.protocol.NavBarRequest>({
246+
command: ts.server.protocol.CommandTypes.NavBar,
247247
arguments: { file: f1.path }
248-
} as ts.server.protocol.NavBarRequest);
248+
});
249249

250250
// send outlining spans request (normal priority)
251-
session.executeCommandSeq({
252-
command: "outliningSpans",
251+
session.executeCommandSeq<ts.server.protocol.OutliningSpansRequestFull>({
252+
command: ts.server.protocol.CommandTypes.GetOutliningSpansFull,
253253
arguments: { file: f1.path }
254-
} as ts.server.protocol.OutliningSpansRequestFull);
254+
});
255255

256256
// ensure the outlining spans request can be canceled
257-
verifyExecuteCommandSeqIsCancellable({
258-
command: "outliningSpans",
257+
verifyExecuteCommandSeqIsCancellable<ts.server.protocol.OutliningSpansRequestFull>({
258+
command: ts.server.protocol.CommandTypes.GetOutliningSpansFull,
259259
arguments: { file: f1.path }
260-
} as ts.server.protocol.OutliningSpansRequestFull);
260+
});
261261
}
262262

263263
function verifyExecuteCommandSeqIsCancellable<T extends ts.server.protocol.Request>(request: TestSessionRequest<T>) {

0 commit comments

Comments
 (0)