# Having trouble using types defined in extension modules?

**URL:** https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260
**Category:** General Usage
**Created:** [April 8, 2023, 9:35pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260 "2023-04-08T21:35:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [April 8, 2023, 9:35pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/1 "2023-04-08T21:35:11Z")

</div>

My setup is on Julia 1.9 I have a package `Foo`, it has an extension module `FooBarExt`, and in that I define a type `MyFooBarType`.

Then from another module I want to do:

```julia
using Foo, Bar
foo(::MyFooBarType) = ...

```

But I can’t figure out how to access `MyFooBarType` in a method definition in a compiled module. I’ve tried these

```julia
foo(::Base.get_extension(Foo,:FooBarExt).MyFooBarType) = ...
@init @eval foo(::Base.get_extension(Foo,:FooBarExt).MyFooBarType) = ...

```

but in both cases `Base.get_extension(Foo,:FooBarExt)` returns nothing, I guess extension modules are loaded later? If this were a function intead of a type, I could just create a stub `function foo end` in `Foo` and use it anywhere, but I don’t know how to do this with a type. Any suggestions?

---

<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: [April 8, 2023, 9:42pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/2 "2023-04-08T21:42:50Z")

</div>

> [@marius311](#):
>
> but I don’t know how to do this with a type. A

I guess move the type definition from `FooBarExt` into `Foo`?

technically because your last package depends on both `Foo` and `Bar` Julia should somehow know for sure `FooBarExt` will be loaded but it doesn’t due to either design or implementation flaw? I think there may be some lazy or eager loading going on

---

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [April 8, 2023, 9:44pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/3 "2023-04-08T21:44:18Z")

</div>

> [@jling](#):
>
> I guess move the type definition from `FooBarExt` into `Foo`?

Yea I thought about this but the type definition needs types from Bar so I can’t do that.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [April 8, 2023, 10:26pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/4 "2023-04-08T22:26:50Z")

</div>

Presumably you’d want this type to be accessible in a module which uses both Foo and Bar, but if so where would the definition come from? It would be strange for a definition from some package you didn’t actually import in any way to appear in your module. You could potentially make a parametric type.

---

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [April 8, 2023, 10:28pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/5 "2023-04-08T22:28:43Z")

</div>

> [@StefanKarpinski](#):
>
> It would be strange for a definition from some package you didn’t actually import in any way to appear in your module

I don’t need it to look exactly like `foo(::MyFooBarType)` sorry if that was confusing. I just can’t figure out _any_ way to get at that type, including using `Base.get_extension`.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [April 9, 2023, 3:11pm UTC](https://discourse.julialang.org/t/having-trouble-using-types-defined-in-extension-modules/97260/6 "2023-04-09T15:11:25Z")

</div>

I think this should be fixed by [Revert "delay loading of extensions as much as possible (#48674)" by KristofferC · Pull Request #49257 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/49257) (see the added tests).
