Skip to content

Support for type aliasing #1315

@luis-j-soares

Description

@luis-j-soares

Similar to what typescript already offers (docs), it would be useful to have a way of naming new types.

Imagine the following use-case:

function sum(a, b)

If we want to give it types but make it generic enough for all value types, a type alias would be great here1:

typealias Number = Integer or LongInteger or Float or Double

function sum(a as Number, b as Number) as Number

Without type aliasing, we'll have to do this, which is somewhat verbose:

function sum(a as Integer or LongInteger or Float or Double, b as Integer or LongInteger or Float or Double) as Integer or LongInteger or Float or Double

A question also remains: should the definition be restricted in scope to the file/namespace like typecast and alias, or should it be project-wide like const and interface? The latter makes more sense to me.

Footnotes

  1. typealias is probably not a great name... I'd name it type but then it'll clash with the built-in type() function. And alias is already taken. Suggestions welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions