Great article as usual! So have you tried using Entity Framework Core (EFCore) with the non-nullable references?
I’m wondering if that improves things.
For instance, in some ORMs a findById operation returns T but in reality, a findByIdoperation always has the potential to not find the item. So the correct return type is T | null.
It’s just another good example of communicating intent.
generics and nullable won't play nicely
I yet have to experiment, but bear in mind that this nullable feature when used on generics requires you to express whether the generic type is either a reference type or a value type (aka where T: class or where T: struct). And since you can't combine both constraints - well... :) It leaves me wondering ;)
Great article as usual! So have you tried using Entity Framework Core (EFCore) with the non-nullable references?
I’m wondering if that improves things.
For instance, in some ORMs a
findById
operation returnsT
but in reality, afindById
operation always has the potential to not find the item. So the correct return type isT | null
.It’s just another good example of communicating intent.
“Communicating your needs” / TypeScript’s value from a Buddhist perspective (part 1)
Cubicle Buddha ・ May 29 ・ 4 min read
generics and nullable won't play nicely
I yet have to experiment, but bear in mind that this nullable feature when used on generics requires you to express whether the generic type is either a reference type or a value type (aka where T: class or where T: struct). And since you can't combine both constraints - well... :) It leaves me wondering ;)
Interesting. I’d love to hear your findings after you experiment. If you write an article, please link it here. :)