I'm working with these specific types and conversion function:
type LeftRightField = null |
{ left: null, right: number } |
{ left: number, right: null } |
{ left: number, right: number }
type LeftRightArray = [null, number] |
[number, null] |
[number, number] |
null
const fmtField = function (field: LeftRightField): LeftRightArray {
const rightField = field?.right ?? null
const leftField = field?.left ?? null
return (leftField == null && rightField == null) ? null : [leftField, rightField]
}
This however fails with an error message stating:
Type 'number | null' is not assignable to type 'null'.
Type 'number' is not assignable to type 'null'
Can you suggest the correct approach for this conversion?