Skip to content

Commit

Permalink
Replace a few type assertions with annotations and satisfies. (micr…
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser authored Dec 6, 2022
1 parent af1d91d commit 3c99d50
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 68 deletions.
12 changes: 6 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2410,10 +2410,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (sourceSymbolFile && targetSymbolFile && amalgamatedDuplicates && !isEitherEnum && sourceSymbolFile !== targetSymbolFile) {
const firstFile = comparePaths(sourceSymbolFile.path, targetSymbolFile.path) === Comparison.LessThan ? sourceSymbolFile : targetSymbolFile;
const secondFile = firstFile === sourceSymbolFile ? targetSymbolFile : sourceSymbolFile;
const filesDuplicates = getOrUpdate(amalgamatedDuplicates, `${firstFile.path}|${secondFile.path}`, () =>
({ firstFile, secondFile, conflictingSymbols: new Map() } as DuplicateInfoForFiles));
const conflictingSymbolInfo = getOrUpdate(filesDuplicates.conflictingSymbols, symbolName, () =>
({ isBlockScoped: isEitherBlockScoped, firstFileLocations: [], secondFileLocations: [] } as DuplicateInfoForSymbol));
const filesDuplicates = getOrUpdate(amalgamatedDuplicates, `${firstFile.path}|${secondFile.path}`, (): DuplicateInfoForFiles =>
({ firstFile, secondFile, conflictingSymbols: new Map() }));
const conflictingSymbolInfo = getOrUpdate(filesDuplicates.conflictingSymbols, symbolName, (): DuplicateInfoForSymbol =>
({ isBlockScoped: isEitherBlockScoped, firstFileLocations: [], secondFileLocations: [] }));
if (!isSourcePlainJs) addDuplicateLocations(conflictingSymbolInfo.firstFileLocations, source);
if (!isTargetPlainJs) addDuplicateLocations(conflictingSymbolInfo.secondFileLocations, target);
}
Expand Down Expand Up @@ -5070,7 +5070,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

interface ExportCollisionTracker {
specifierText: string;
exportsWithDuplicate: ExportDeclaration[];
exportsWithDuplicate?: ExportDeclaration[];
}

type ExportCollisionTrackerTable = UnderscoreEscapedMap<ExportCollisionTracker>;
Expand All @@ -5090,7 +5090,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (lookupTable && exportNode) {
lookupTable.set(id, {
specifierText: getTextOfNode(exportNode.moduleSpecifier!)
} as ExportCollisionTracker);
});
}
}
else if (lookupTable && exportNode && targetSymbol && resolveSymbol(targetSymbol) !== resolveSymbol(sourceSymbol)) {
Expand Down
6 changes: 3 additions & 3 deletions src/harness/vfsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ export class FileSystem {
private _mknod(dev: number, type: typeof S_IFREG, mode: number, time?: number): FileInode;
private _mknod(dev: number, type: typeof S_IFDIR, mode: number, time?: number): DirectoryInode;
private _mknod(dev: number, type: typeof S_IFLNK, mode: number, time?: number): SymlinkInode;
private _mknod(dev: number, type: number, mode: number, time = this.time()) {
private _mknod(dev: number, type: number, mode: number, time = this.time()): Inode {
return {
dev,
ino: ++inoCount,
Expand All @@ -886,7 +886,7 @@ export class FileSystem {
ctimeMs: time,
birthtimeMs: time,
nlink: 0
} as Inode;
};
}

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

if (isSymlink(root)) (shadow as SymlinkInode).symlink = root.symlink;
shadows.set(shadow.ino, shadow);
Expand Down
2 changes: 1 addition & 1 deletion src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@ export class ProjectService {
this.eventHandler({
eventName: ConfigFileDiagEvent,
data: { configFileName: project.getConfigFilePath(), diagnostics, triggerFile }
} as ConfigFileDiagEvent);
} satisfies ConfigFileDiagEvent);
}

private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined {
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/parallel/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ export function start() {
}
worker.currentTasks = taskList;
if (taskList.length === 1) {
worker.process.send({ type: "test", payload: taskList[0] } as ParallelHostMessage); // TODO: GH#18217
worker.process.send({ type: "test", payload: taskList[0] } satisfies ParallelHostMessage); // TODO: GH#18217
}
else {
worker.process.send({ type: "batch", payload: taskList } as ParallelHostMessage); // TODO: GH#18217
worker.process.send({ type: "batch", payload: taskList } satisfies ParallelHostMessage); // TODO: GH#18217
}
}
}
Expand Down
112 changes: 56 additions & 56 deletions src/testRunner/unittests/tsserver/cancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ describe("unittests:: tsserver:: cancellationToken", () => {
const session = createSession(host, { cancellationToken });

expectedRequestId = session.getNextSeq();
session.executeCommandSeq({
command: "open",
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
command: ts.server.protocol.CommandTypes.Open,
arguments: { file: f1.path }
} as ts.server.protocol.OpenRequest);
});

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

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

expectedRequestId = 2;
host.runQueuedImmediateCallbacks();
Expand Down Expand Up @@ -82,15 +82,15 @@ describe("unittests:: tsserver:: cancellationToken", () => {
cancellationToken
});
{
session.executeCommandSeq({
command: "open",
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
command: ts.server.protocol.CommandTypes.Open,
arguments: { file: f1.path }
} as ts.server.protocol.OpenRequest);
});
// send geterr for missing file
session.executeCommandSeq({
command: "geterr",
arguments: { files: ["/a/missing"] }
} as ts.server.protocol.GeterrRequest);
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
command: ts.server.protocol.CommandTypes.Geterr,
arguments: { files: ["/a/missing"], delay: 0 }
});
// Queued files
assert.equal(host.getOutput().length, 0, "expected 0 message");
host.checkTimeoutQueueLengthAndRun(1);
Expand All @@ -101,18 +101,18 @@ describe("unittests:: tsserver:: cancellationToken", () => {
{
const getErrId = session.getNextSeq();
// send geterr for a valid file
session.executeCommandSeq({
command: "geterr",
arguments: { files: [f1.path] }
} as ts.server.protocol.GeterrRequest);
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
command: ts.server.protocol.CommandTypes.Geterr,
arguments: { files: [f1.path], delay: 0 }
});

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

// run new request
session.executeCommandSeq({
command: "projectInfo",
arguments: { file: f1.path }
} as ts.server.protocol.ProjectInfoRequest);
session.executeCommandSeq<ts.server.protocol.ProjectInfoRequest>({
command: ts.server.protocol.CommandTypes.ProjectInfo,
arguments: { file: f1.path, needFileNameList: false }
});
session.clearMessages();

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

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

// run first step
Expand All @@ -178,10 +178,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
}
{
const getErr1 = session.getNextSeq();
session.executeCommandSeq({
command: "geterr",
arguments: { files: [f1.path] }
} as ts.server.protocol.GeterrRequest);
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
command: ts.server.protocol.CommandTypes.Geterr,
arguments: { files: [f1.path], delay: 0 }
});
assert.equal(host.getOutput().length, 0, "expect 0 messages");
// run first step
host.runQueuedTimeoutCallbacks();
Expand All @@ -190,10 +190,10 @@ describe("unittests:: tsserver:: cancellationToken", () => {
assert.equal(e1.event, "syntaxDiag");
session.clearMessages();

session.executeCommandSeq({
command: "geterr",
arguments: { files: [f1.path] }
} as ts.server.protocol.GeterrRequest);
session.executeCommandSeq<ts.server.protocol.GeterrRequest>({
command: ts.server.protocol.CommandTypes.Geterr,
arguments: { files: [f1.path], delay: 0 }
});
// make sure that getErr1 is completed
verifyRequestCompleted(getErr1, 0);
}
Expand Down Expand Up @@ -230,34 +230,34 @@ describe("unittests:: tsserver:: cancellationToken", () => {
throttleWaitMilliseconds: 0
});
{
session.executeCommandSeq({
command: "open",
session.executeCommandSeq<ts.server.protocol.OpenRequest>({
command: ts.server.protocol.CommandTypes.Open,
arguments: { file: f1.path }
} as ts.server.protocol.OpenRequest);
});

// send navbar request (normal priority)
session.executeCommandSeq({
command: "navbar",
session.executeCommandSeq<ts.server.protocol.NavBarRequest>({
command: ts.server.protocol.CommandTypes.NavBar,
arguments: { file: f1.path }
} as ts.server.protocol.NavBarRequest);
});

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

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

// ensure the outlining spans request can be canceled
verifyExecuteCommandSeqIsCancellable({
command: "outliningSpans",
verifyExecuteCommandSeqIsCancellable<ts.server.protocol.OutliningSpansRequestFull>({
command: ts.server.protocol.CommandTypes.GetOutliningSpansFull,
arguments: { file: f1.path }
} as ts.server.protocol.OutliningSpansRequestFull);
});
}

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

0 comments on commit 3c99d50

Please sign in to comment.