Skip to content

Commit f3ee56d

Browse files
committed
refactor(validation): refactor type assertions to proper type guards in structural-class validation
Replace 'as number | undefined' and 'as string | undefined' type assertions with proper typeof checks to improve type safety and comply with no-assertion policy. Changes: - permutationValue: typeof value === "number" ? value : 0 - topologicalOrder: typeof value === "number" ? value : 0 - perfectClass: value === perfectClass && typeof value === "string"
1 parent 5aa75b6 commit f3ee56d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/validation/structural-class.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ export const validatePermutation = (graph: TestGraph): PropertyValidationResult
482482
// Check if stored permutation data exists
483483
const hasPermutationData = nodes.every(n => n.data?.permutationValue !== undefined);
484484
if (hasPermutationData) {
485-
const permutation = nodes.map(n => (n.data?.permutationValue as number | undefined) ?? 0);
485+
const permutation = nodes.map(n => {
486+
const value = n.data?.permutationValue;
487+
return typeof value === "number" ? value : 0;
488+
});
486489

487490
// Verify edges match permutation pattern
488491
const adjacency = new Map<string, Set<string>>();
@@ -564,7 +567,10 @@ export const validateComparability = (graph: TestGraph): PropertyValidationResul
564567
if (hasTopologicalOrder) {
565568
// If generated with topological order, verify it's a valid DAG orientation
566569
// For now, just check that the stored order is consistent
567-
const orders = nodes.map(n => (n.data?.topologicalOrder as number | undefined) ?? 0);
570+
const orders = nodes.map(n => {
571+
const value = n.data?.topologicalOrder;
572+
return typeof value === "number" ? value : 0;
573+
});
568574
const uniqueOrders = new Set(orders);
569575

570576
if (uniqueOrders.size !== nodes.length) {
@@ -642,7 +648,10 @@ export const validatePerfect = (graph: TestGraph): PropertyValidationResult => {
642648
const perfectClass = nodes[0].data?.perfectClass;
643649

644650
// Verify all nodes have the same class
645-
const consistentClass = nodes.every(n => (n.data?.perfectClass as string | undefined) === perfectClass);
651+
const consistentClass = nodes.every(n => {
652+
const value = n.data?.perfectClass;
653+
return value === perfectClass && typeof value === "string";
654+
});
646655
if (!consistentClass) {
647656
return {
648657
property: "perfect",

0 commit comments

Comments
 (0)