# Annotating global variable's type (v1.8) but only known at runtime

**URL:** https://discourse.julialang.org/t/annotating-global-variables-type-v1-8-but-only-known-at-runtime/82016
**Category:** General Usage
**Created:** [May 31, 2022, 9:44pm UTC](https://discourse.julialang.org/t/annotating-global-variables-type-v1-8-but-only-known-at-runtime/82016 "2022-05-31T21:44:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [May 31, 2022, 9:44pm UTC](https://discourse.julialang.org/t/annotating-global-variables-type-v1-8-but-only-known-at-runtime/82016/1 "2022-05-31T21:44:21Z")

</div>

I’m thinking about how in v1.8 you can annotate a global variable with a fixed type e.g. `a::Int = 4`. Is there a way to specify the variable has a fixed type but it’s inferred from the runtime value at assignment? It happens with `const` e.g. `const a = 3.5im * 5im`, but of course the value is assumed constant there as well.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [June 1, 2022, 2:09am UTC](https://discourse.julialang.org/t/annotating-global-variables-type-v1-8-but-only-known-at-runtime/82016/2 "2022-06-01T02:09:32Z")

</div>

> [@Seven Lines of Julia (examples sought)](https://discourse.julialang.org/t/seven-lines-of-julia-examples-sought/50416/157):
>
> In Julia v1.8 we’ll have the possibility of type-annotating global variables, to promise their type won’t change: julia\> x::Float64 = 3.14 3.14 julia\> x = 2.71 2.71 julia\> x = "hello world" ERROR: MethodError: Cannot `convert` an object of type String to an object of type Float64 Wouldn’t it be nice if we could automatically get the type annotation without having to explicitly type it ourselves? Here be dragons macros (note that the macro definition is exactly 7 lines): julia\> macro stable…
