Remove unnecessary type assertions across codebase

Add oxlint-tsgolint and configure typescript/no-unnecessary-type-assertion
to flag redundant `!` and `as Foo` casts. Type-aware mode is left off by
default to keep `npm run lint` fast; the rule sits configured for when we
turn type-aware on intentionally. Auto-fix removed ~283 redundant casts;
two manual touch-ups: a real tsgolint false positive in split-container.tsx
and a stale ChildProcess import after a double-cast collapsed.
This commit is contained in:
Mohamed Boudra
2026-05-04 10:21:52 +07:00
parent 78fe3e4df3
commit 4cd9e76bd2
129 changed files with 409 additions and 323 deletions

View File

@@ -44,7 +44,7 @@ export async function runArchiveCommand(
options: AgentArchiveOptions,
_command: Command,
): Promise<AgentArchiveCommandResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!agentIdArg || agentIdArg.trim().length === 0) {
@@ -58,7 +58,7 @@ export async function runArchiveCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {

View File

@@ -105,7 +105,7 @@ export async function runAttachCommand(
options: AgentAttachOptions,
_command: Command,
): Promise<void> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
if (!id) {
console.error("Error: Agent ID required");
@@ -115,7 +115,7 @@ export async function runAttachCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
console.error(`Error: Cannot connect to daemon at ${host}: ${message}`);

View File

@@ -113,7 +113,7 @@ export async function runImportCommand(
options: AgentImportOptions,
_command: Command,
): Promise<AgentImportCommandResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
const sessionId = sessionIdArg.trim();
if (!sessionId) {
throw {
@@ -134,7 +134,7 @@ export async function runImportCommand(
}
const labels = parseImportLabels(options.label);
const client = await connectToDaemonOrThrow(options.host as string | undefined, host);
const client = await connectToDaemonOrThrow(options.host, host);
try {
const agent = await client.importAgent({

View File

@@ -216,7 +216,7 @@ export async function runInspectCommand(
options: AgentInspectOptions,
_command: Command,
): Promise<AgentInspectResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!agentIdArg || agentIdArg.trim().length === 0) {
@@ -230,7 +230,7 @@ export async function runInspectCommand(
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {

View File

@@ -40,7 +40,7 @@ export async function runReloadCommand(
options: AgentReloadOptions,
_command: Command,
): Promise<AgentReloadCommandResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
if (!agentIdArg || agentIdArg.trim().length === 0) {
const error: CommandError = {
@@ -53,7 +53,7 @@ export async function runReloadCommand(
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {

View File

@@ -86,7 +86,7 @@ export async function runUpdateCommand(
options: AgentUpdateOptions,
_command: Command,
): Promise<AgentUpdateCommandResult> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!agentIdArg || agentIdArg.trim().length === 0) {
@@ -120,7 +120,7 @@ export async function runUpdateCommand(
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {

View File

@@ -139,7 +139,7 @@ export async function runWaitCommand(
options: AgentWaitOptions,
_command: Command,
): Promise<SingleResult<AgentWaitResult>> {
const host = getDaemonHost({ host: options.host as string | undefined });
const host = getDaemonHost({ host: options.host });
if (!agentIdArg || agentIdArg.trim().length === 0) {
throw {
@@ -153,7 +153,7 @@ export async function runWaitCommand(
let client;
try {
client = await connectToDaemon({ host: options.host as string | undefined });
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {

View File

@@ -32,7 +32,7 @@ export async function runPostCommand(
]);
return {
type: "single",
data: message!,
data: message,
schema: chatMessageSchema,
};
} catch (err) {

View File

@@ -12,7 +12,7 @@ export function pairCommand(): Command {
return addJsonOption(new Command("pair").description("Print the daemon pairing QR code and link"))
.option("--home <path>", "Paseo home directory (default: ~/.paseo)")
.action(async (_options: PairOptions, command: Command) => {
await runPairCommand(command.optsWithGlobals() as PairOptions);
await runPairCommand(command.optsWithGlobals());
});
}

View File

@@ -84,7 +84,7 @@ async function resolveNodePathFromPidWindows(pid: number): Promise<NodePathFromP
error: errors.join("; ") || "could not resolve executable path from PID",
};
}
const probe = probes[index] as (typeof probes)[number];
const probe = probes[index];
const result = await runProcessProbe(probe.command, probe.args);
if (result.resolved) {
const resolved = probe.parseValue ? probe.parseValue(result.resolved) : result.resolved;

View File

@@ -111,7 +111,7 @@ export async function runAllowCommand(
permissionsToAllow = pendingPermissions;
} else {
// Find permission by ID prefix
const permission = pendingPermissions.find((p) => p.id === reqId || p.id.startsWith(reqId!));
const permission = pendingPermissions.find((p) => p.id === reqId || p.id.startsWith(reqId));
if (!permission) {
await client.close();
const error: CommandError = {

View File

@@ -76,7 +76,7 @@ export async function runLsCommand(
provider: entry.provider,
label: entry.label ?? entry.provider,
status: entry.status === "ready" ? "available" : entry.status,
enabled: entry.enabled === false ? "Disabled" : "Enabled",
enabled: !entry.enabled ? "Disabled" : "Enabled",
defaultMode: entry.defaultModeId ?? "default",
modes: (entry.modes ?? []).map((mode) => mode.label).join(", "),
})),

View File

@@ -137,7 +137,7 @@ export function renderTable<T>(result: AnyCommandResult<T>, options: OutputOptio
return "";
}
const columns = schema.columns as ColumnDef<T>[];
const columns = schema.columns;
const includeHeaders = !options.noHeaders;
const widths = calculateWidths(data, columns, includeHeaders);

View File

@@ -342,7 +342,7 @@ export async function connectToDaemon(options?: ConnectOptions): Promise<DaemonC
if (lastError instanceof Error) throw lastError;
throw new Error(`Unable to connect to Paseo daemon via ${hosts.join(", ")}`);
}
const host = hosts[index] as string;
const host = hosts[index];
const password = resolveDaemonPassword(host);
const result = await tryConnectHost(host, password, clientId, timeout, nodeWebSocketFactory);
if ("client" in result) {