Is there any library similar to Typescript for Julia?

Is there any library similar to Typescript for Julia?

example.ts

let a: number = 1 ;
console.log(a) // output: 1

example.jl

# Assign the value 10 to the variable x
julia> x = 10
10

example.jl

# Assign the value 10 to the variable x
julia> x:number = 10
10

reference

Julia has a type system built-in, so there is no need to build a library on top for type support.

For example, the TypeScript website shows

interface Account {
  id: number
  displayName: string
  version: 1
}
 
function welcome(user: Account) {
  console.log(user.id)
}

In Julia, you can write this as

julia> Base.@kwdef struct Account
           id::Number
           name::String
           version::Int = 1
       end;

julia> function welcome(user::Account)
           println("Welcome $(user.name)!")
       end;

julia> user = Account(; id=1, name="Sally")
Account(1, "Sally", 1)

julia> welcome(user)
Welcome Sally!
4 Likes

Julia supports annotating the type of local variables and intends to support the same for global variables types:

julia> let
       x::Int = 1
       end
1

julia> y::Int = 1
ERROR: syntax: type declarations on global variables are not yet supported
Stacktrace:
 [1] top-level scope at REPL[2]:1

In fact, I am using Julia 1.5.3, maybe the most recent Julia versions already support annotating the type of global variables.

4 Likes

v1.8 does

4 Likes

please, close topic here.