# Typing Syntax: Forward Reference Union Type

**URL:** <https://discuss.python.org/t/typing-syntax-forward-reference-union-type/74563>\
**Category:** Typing\
**Created:** [December 17, 2024, 7:55pm UTC](https://discuss.python.org/t/typing-syntax-forward-reference-union-type/74563 "2024-12-17T19:55:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spill\_the\_Tea](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@Spill\_the\_Tea](https://discuss.python.org/u/Spill_the_Tea)\
**Post date:** [December 17, 2024, 7:55pm UTC](https://discuss.python.org/t/typing-syntax-forward-reference-union-type/74563/1 "2024-12-17T19:55:06Z")

</div>

Build on PEP484 and PEP604 to permit the newer union type syntax annotations with Forward References. See the following syntax:

```python

class Example:
    a: int | "Forward"
    b: float

def function(a: int | "Forward"): ...

class Forward:
    a: int

```

Currently, this syntax raises the following error:  
`TypeError: unsupported operand type(s) for |: 'type' and 'str'`

The current workaround is to use the previous union type annotation:

```python
from typing import Union

class Example:
    a: Union[int, "Forward"]

```

---

<div class="post-metadata">

**Author:** ![erictraut](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erictraut/32/15190_2.png) [@erictraut](https://discuss.python.org/u/erictraut)\
**Post date:** [December 17, 2024, 8:41pm UTC](https://discuss.python.org/t/typing-syntax-forward-reference-union-type/74563/2 "2024-12-17T20:41:28Z")

</div>

More typically, you would enclose the entire annotation in quotes, which avoids this issue.

```python
a: "int | Forward"

```

Alternatively, use `from __future__ import annotations`, which eliminates the need to use quotes altogether.
