Skip to content

Use reflect.TypeFor instead of reflect.TypeOf((*T)(nil)).Elem()#4949

Merged
pietern merged 1 commit intomainfrom
go1.22-reflect-typefor
Apr 15, 2026
Merged

Use reflect.TypeFor instead of reflect.TypeOf((*T)(nil)).Elem()#4949
pietern merged 1 commit intomainfrom
go1.22-reflect-typefor

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Apr 13, 2026

Summary

  • Replace the verbose reflect.TypeOf((*T)(nil)).Elem() idiom with reflect.TypeFor[T](), available since Go 1.22
  • Delete the now-redundant calladapt.TypeOf helper
  • Add a ruleguard lint rule to prevent reintroduction

Test plan

  • go build ./...
  • go test for all modified packages
  • golangci-lint run ./... passes
  • Verified lint rule fires on the old pattern

This pull request was AI-assisted by Isaac.

Replace the verbose pre-Go 1.22 idiom with `reflect.TypeFor[T]()`,
added in Go 1.22 (https://go.dev/doc/go1.22#reflect). Delete the
now-redundant `calladapt.TypeOf` helper and add a ruleguard lint
rule to prevent reintroduction of the old pattern.

Co-authored-by: Isaac
@pietern pietern added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 4fc00e4 Apr 15, 2026
24 checks passed
@pietern pietern deleted the go1.22-reflect-typefor branch April 15, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants