# @isdefined in eltype implementation

**URL:** https://discourse.julialang.org/t/isdefined-in-eltype-implementation/77759
**Category:** General Usage
**Tags:** question
**Created:** [March 11, 2022, 4:05pm UTC](https://discourse.julialang.org/t/isdefined-in-eltype-implementation/77759 "2022-03-11T16:05:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [March 11, 2022, 4:05pm UTC](https://discourse.julialang.org/t/isdefined-in-eltype-implementation/77759/1 "2022-03-11T16:05:21Z")

</div>

Hi,

I’m trying to figure out what `@isdefined` is doing [here](https://github.com/JuliaLang/julia/blob/master/base/abstractarray.jl#L207):

```julia
eltype(::Type{<:AbstractArray{E}}) where {E} = @isdefined(E) ? E : Any

```

How can `E` _not_ be defined at this point?

Thanks

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 11, 2022, 4:35pm UTC](https://discourse.julialang.org/t/isdefined-in-eltype-implementation/77759/2 "2022-03-11T16:35:04Z")

</div>

OK, here is an example

```julia
import Base.eltype
eltype(::Type{<:AbstractArray{E}}) where {E} = @isdefined(E) ? E : @assert false

@show eltype(Vector{Number}) 
@show eltype(Vector{Unknown}) where Unknown

```

Pretty sophisticated check there…

---

<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: [March 11, 2022, 4:54pm UTC](https://discourse.julialang.org/t/isdefined-in-eltype-implementation/77759/3 "2022-03-11T16:54:03Z")

</div>

In general methods can get called and not all type parameters resolve to something. A more clear example might be:

```julia
foo(args::T...) where {T} = @isdefined(T)
foo() # false

```

I can’t think of a great example for `eltype` there, but e.g. `eltype(Base.unwrap_unionall(Vector))` is hitting that branch. Corner case no doubt, but you wouldn’t want that to error otherwise.
