4 ms·
When people mention type safety in this context, they are talking about compiler guarantees. Application code that uses type assertions will never be "type safe
by collinvandyck76 3y ago
When people mention type safety in this context, they are talking about compiler guarantees. Application code that uses type assertions will never be "type safe" in the way that a compiler can ensure. So while you're correct that if the application code that does the type checking is bug free then the type safety is implied, but is not certain in all cases.
- adamwk 3y agoSure but the interface is typesafe and usually that’s good enough. The two methods of the API (NewContext and FromContext) are typesafe from the perspective of the user.
- ilyt 3y agoWe're talking about context variables which are of type any so you need to check them runtime.
- yencabulator 3y agoThe guarantee you don't get is that foo.FromContext always succeeds. If *Foo was a struct field of your receiver or an argument to the function, the function would be guaranteed to have access to a *Foo.