Skip to content

Commit e01adda

Browse files
committed
refactor: replace type assertion with type guard in flushOutput
Extract isIdentifiable() type guard to replace unsafe 'as' cast, improving type safety in PrinterObserver.flushOutput().
1 parent 4a77b81 commit e01adda

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

packages/extension/src/Observers/PrinterObserver.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,18 @@ export class PrinterObserver implements TestRunnerObserver {
9494
return;
9595
}
9696

97-
const testId = result && 'id' in result ? result.id : undefined;
98-
const location =
99-
result && 'file' in result
100-
? this.toLocation(
101-
result as TestResultIdentify & { details?: TestFailed['details'] },
102-
)
103-
: undefined;
104-
this.append(output, location, testId);
97+
if (!result || !this.isIdentifiable(result)) {
98+
this.append(output);
99+
return;
100+
}
101+
102+
this.append(output, this.toLocation(result), result.id);
103+
}
104+
105+
private isIdentifiable(
106+
result: TestResult,
107+
): result is TestResult & TestResultIdentify & { details?: TestFailed['details'] } {
108+
return 'id' in result && 'file' in result;
105109
}
106110

107111
private toLocation(

0 commit comments

Comments
 (0)