# How @TypeOf chooses the resulting type when there are more than one arguments

**URL:** <https://ziggit.dev/t/how-typeof-chooses-the-resulting-type-when-there-are-more-than-one-arguments/3265>\
**Category:** Help\
**Tags:** language\
**Created:** [February 15, 2024, 8:26pm UTC](https://ziggit.dev/t/how-typeof-chooses-the-resulting-type-when-there-are-more-than-one-arguments/3265 "2024-02-15T20:26:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [February 15, 2024, 8:26pm UTC](https://ziggit.dev/t/how-typeof-chooses-the-resulting-type-when-there-are-more-than-one-arguments/3265/1 "2024-02-15T20:26:10Z")

</div>

The following program, prints:

```zig
> zig run typeof.zig
a:comptime_int b:u8 T:u8

> cat typeof.zig
const std = @import("std");

fn foo(a: anytype, b: anytype) void {
    const T = @TypeOf(a, b);
    std.debug.print("a:{s} b:{s} T:{s}\n", .{
        @typeName(@TypeOf(a)),
        @typeName(@TypeOf(b)),
        @typeName(T),
    });
}

pub fn main() void {
    const v: u8 = 'a';
    foo(32, v);
}

```

In master testing.zig `expectEqual` is declared as:

```zig
pub inline fn expectEqual(expected: anytype, actual: anytype) !void {
    const T = @TypeOf(expected, actual);

```

In 0.11.0 testing.zig `expectEqual` is declared as:

```zig
pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {

```

A headache with expectEqual is gone, but how @TypeOf selects the resulting type?

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [February 15, 2024, 8:48pm UTC](https://ziggit.dev/t/how-typeof-chooses-the-resulting-type-when-there-are-more-than-one-arguments/3265/2 "2024-02-15T20:48:43Z")

</div>

[Language Reference: @TypeOf](https://ziglang.org/documentation/master/#toc-TypeOf)

> `@TypeOf` is a special builtin function that takes any (nonzero) number of expressions as parameters and returns the type of the result, using [Peer Type Resolution](https://ziglang.org/documentation/master/#Peer-Type-Resolution).

Peer Type Resolution:

> This kind of type resolution chooses a type that all peer types can coerce into.

* * *

I think there may be more to explain and explore in detail here, that is just the first few things I found.
