mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 03:09:39 -06:00
Replace a few type assertions with annotations and satisfies. (#51685)
This commit is contained in:
parent
af1d91d9d9
commit
3c99d50da5
@ -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);
|
||||
}
|
||||
@ -5070,7 +5070,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
|
||||
interface ExportCollisionTracker {
|
||||
specifierText: string;
|
||||
exportsWithDuplicate: ExportDeclaration[];
|
||||
exportsWithDuplicate?: ExportDeclaration[];
|
||||
}
|
||||
|
||||
type ExportCollisionTrackerTable = UnderscoreEscapedMap<ExportCollisionTracker>;
|
||||
@ -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)) {
|
||||
|
||||
@ -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,
|
||||
@ -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()) {
|
||||
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
@ -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);
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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();
|
||||
@ -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);
|
||||
}
|
||||
@ -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>) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user