The Crystal Programming Language Forum

Use a variable as Type in assignment

hello, everyone, I got this error:

$crystal --version
Crystal 0.30.1 [5e6a1b672] (2019-08-12)
$crystal eval 'u = Int32|String; y : Int32|String = 4 ;puts y '

$crystal eval 'u = Int32|String; y : u = 4 ;puts y '
Error: expecting token 'CONST', not 'u'

I want to use variable instead of union types directly, is it possible?

Hi @orangeSi! might be what you need?


yes, thanks a lot! I thought I had read the documnet almost all, but still ignored alias, I will read the Crystal Doc with more attention!

1 Like