Unfortunately, in order to use this proposed version, you still need to pre-declare the variables for each type before the switch/case.
I've honestly found it more ergonomic to use a if/else if/ block rather than a switch/case because it lets me contain the scope of these variables anyway.
I suppose a simple wrapper that can be used with type-assertions inside a switch/case block would be:
```
func AsBool[E error](err error, asErr error) bool {
ae, ok := As[E](err)
if ok {
asErr = ae
}
return ok
}
```
(this would definitely need a better name)
Then you'd be able to almost treat your switch/case like a type-switch without needing to pre-declare a variable for every case.
```
var asErr error
switch {
case errors.AsBool[*os.PathError](err, &asErr):
fmt.Printf("Path Error! ae: %v", asErr.(*os.PathError))
case errors.AsBool[syscall.Errno](err, &asErr):
fmt.Printf("ae: %d", asErr.(syscall.Errno))
}
```
However, I think it would be nicer to use the (originally proposed) two-return errors.As with if/else if.
```
if pe, ok := errors.As[*os.PathError](err); ok {
fmt.Printf("Path Error: %v", pe)
} else if en, ok := errors.As[syscall.Errno](err); ok {
fmt.Printf("errno %[1]d: %[1]s", en)
}
```
Since it looks like the dev.typeparams branch has been merged into master, I was just thinking about how we'd add the two-return-value/generic version of As to the errors package (for go 1.18).
Given that the original proposal's code works pretty much as-is, I think the biggest barrier would be a good name. (given that As is already taken)