The problem here is that the attribute author
in Post
differes from the one in PostWithNull
, in Post
its type is Author
in PostWithNull
its type is Author | null
.
To solve your issue you could change the return type of your function with:
function getPostById(id: string): PostWithNull | null {