# Crystal docs: how to prevent alias expansion?

**URL:** <https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200>\
**Category:** Help & Support\
**Created:** [December 23, 2022, 6:49pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200 "2022-12-23T18:49:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [December 23, 2022, 6:49pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/1 "2022-12-23T18:49:44Z")

</div>

The generation of documentation with “Crystal docs” expands the alias definitions, which does not make the documentation easier to read, and also makes it less relevant, when the alias is a union of many types.

I have not found a solution to avoid this.  
Is there one?

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [December 23, 2022, 7:10pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/2 "2022-12-23T19:10:46Z")

</div>

That shouldn’t be happening. Where do you get an alias resolved?

Example in stdlib docs: [Colorize::Object(T) - Crystal 1.6.2](https://crystal-lang.org/api/1.6.2/Colorize/Object.html#back%28back%3AColor%29%3Aself-instance-method) (`Color` is an alias, it’s not expanded).

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [December 23, 2022, 8:58pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/3 "2022-12-23T20:58:16Z")

</div>

I have just created a minimal test app to illustrate my point.  
Here is the code of the single source file.

```auto
module Test
  alias DataType = Bool | Char | Int32 | Int64 | Float64 | String | Symbol | Time

  struct CellData
    getter value, index

    def initialize(@value : DataType, @index : Int32)
    end
  end

  alias Formatter = Proc(DataType, CellData, String) |
                    Proc(DataType, String)
end  

```

After running `crystal docs`, the HTML files contain:

1. For `struct CellData`:

```auto
def value : Bool | Char | Float64 | Int32 | Int64 | String | Symbol | Time

```

instead of expected:

```auto
def value : DataType

```

1. For `formatter` alias definition :

```auto
Bool | Char | Float64 | Int32 | Int64 | String | Symbol | Time -> String | Bool | Char | Float64 | Int32 | Int64 | String | Symbol | Time, Test::CellData -> String

```

instead of:

```auto
DataType -> String | DataType, CellData, -> String

```

As you can see, both aliases DataType and Formatter are expanded.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [December 23, 2022, 9:25pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/4 "2022-12-23T21:25:30Z")

</div>

Ah, that’s a feature I introduced where the type of getters is deduced if not specified, for docs. You can fix this by specifying the type of the getter to be the alias.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [December 23, 2022, 9:25pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/5 "2022-12-23T21:25:46Z")

</div>

Forgot to say: it’ll be tricky to fix this.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [December 23, 2022, 9:33pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/6 "2022-12-23T21:33:03Z")

</div>

Yeah, the type of `#value` is not declared, so the compiler deduces it. I suppose it could perhaps be more intelligent about it, but that’s just what you get. If you want an explicit type, then declare is explicitly.

That’s for 1. `CellData#value`.

The other examples (2.) about `alias Formatter` is a different story. That looks like an actual bug because what the doc generator produces here is plainly wrong. That’s not even valid syntax for the type grammar.

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [December 23, 2022, 9:59pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/7 "2022-12-23T21:59:23Z")

</div>

It works with

```auto
getter value : DataType

```

Thanks.

I also noticed that replacing

```auto
getter value

```

by

```auto
def value
  @value
end

```

also expands DataType.

---

<div class="post-metadata">

**Author:** ![hutou](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/hutou/32/1337_2.png) [@hutou](https://forum.crystal-lang.org/u/hutou)\
**Post date:** [December 23, 2022, 10:01pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/8 "2022-12-23T22:01:03Z")

</div>

I didn’t notice the generated expanded code for Formatter was incorrect !  
Should I declare an issue for that ?

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [December 23, 2022, 10:24pm UTC](https://forum.crystal-lang.org/t/crystal-docs-how-to-prevent-alias-expansion/5200/9 "2022-12-23T22:24:31Z")

</div>

> [@hutou](#):
>
> also expands DataType

Right, that’s the general rule that was added to the docs generator. I’m wondering if if we should revert that rule.
