# Typealias with a custom constructor

**URL:** <https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463>\
**Category:** General Usage\
**Tags:** type\
**Created:** [November 14, 2021, 7:30pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463 "2021-11-14T19:30:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [November 14, 2021, 7:30pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/1 "2021-11-14T19:30:01Z")

</div>

Is there a way to create a type alias with a custom constructor?

```julia
FloatyMcFloatFace = Float64
FloatyMcFloatFace(x) = new(x+1)

```

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [November 14, 2021, 8:06pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/2 "2021-11-14T20:06:09Z")

</div>

No. Aliases are just another name for exactly the same type, so they can’t have separate methods.

---

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [November 14, 2021, 8:19pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/3 "2021-11-14T20:19:49Z")

</div>

Is there a good way to have a custom type that automatically inherits all the methods of the “aliased” type? I would like to have a custom type that has all the properties and functions of a Matrix but has custom show and constructors.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 14, 2021, 8:42pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/4 "2021-11-14T20:42:46Z")

</div>

You have to implement some methods and make your type a subtype of AbstractMatrix: [Interfaces · The Julia Language](https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array)

---

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [November 14, 2021, 8:52pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/5 "2021-11-14T20:52:18Z")

</div>

I was trying to avoid that. `Matrix` type is fairly well documented but for a lot of types that would mean run the code and implement the method from the error stack trace. I need a catch all 🙂

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [November 14, 2021, 9:03pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/6 "2021-11-14T21:03:58Z")

</div>

[https://docs.juliahub.com/Lazy/mi7Ul/0.15.0/autodocs/#Lazy.@forward-Tuple{Any,Any}](https://docs.juliahub.com/Lazy/mi7Ul/0.15.0/autodocs/#Lazy.@forward-Tuple%7BAny,Any%7D)

could help but you can’t avoid doing:

> [@owiecc](#):
>
> run the code and implement the method from the error stack trace

---

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [November 14, 2021, 9:17pm UTC](https://discourse.julialang.org/t/typealias-with-a-custom-constructor/71463/7 "2021-11-14T21:17:17Z")

</div>

`Lazy.@forward` looks great. Thanks!
