torch.ValidatedEinsumShape
export type ValidatedEinsumShape<E extends string, Shapes extends readonly Shape[]> =
// Step 1: Check if validation failed (returned an error type)
ValidateEinsum<E, Shapes> extends { readonly __isShapeError: true }
? // Validation failed: extract and return the error type
ValidateEinsum<E, Shapes> & readonly number[]
: // Validation passed: return the output shape
EinsumOutputShape<E, Shapes> & readonly number[];Eextends stringShapesextends readonly Shape[]Validated einsum output shape.
This type is designed to:
- Return error types that show clearly in TypeScript error messages
- Return output shapes that preserve exact dimensions
- Always satisfy the Shape constraint (readonly number[])
When validation fails, returns an error shape like einsum_error_operand_count_mismatch.
When validation passes, returns the computed output shape.
The intersection with readonly number[] ensures TypeScript knows the result
is always a valid Shape, while the branded properties on error types still
cause assignability errors that show the error type name.