Here is the type structure I am working with:
type Child = {
foo: number | null
}
type Parent = {
child: Child | null
}
I am looking to create a type-guard function that takes in a Parent
object as a parameter and checks if foo
is a number. Something along the lines of:
const guard = (parent: Parent): parent?.child?.foo is number => {
return isNumber(parent?.child?.foo)
}
Is there a way for TypeScript to infer that parent.child
is not null based on this type-guard function?