question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can we have type aliases?

See original GitHub issue

I would like to be able to create type aliases, namely something like this:

...
type PathToFastq = File
type PathToFasta = File
...
task bwa {
    input {
        PathToFastq read1
        PathToFastq read2
        PathToFasta fasta
        ...
    }
    ...
}

What do other folks think? It would make reading the inputs a lot clearer and would allow folks to alias File to their favorite genomic file format (ex. BED, BAM, XLSX …).

I’d be happy to make a PR; since this is my first time adding to the spec, I wouldn’t mind some help figuring out where it would go.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
DavyCatscommented, Oct 10, 2019

I strongly agree with @patmagee here, names should indicate what the value of the variable represents and types should only indicate how they can be used. If your naming relies on the type to be understandable, you will have to look up its declaration whenever you encounter it at some other point in your code:

NumberOf samples = 12

[...many lines of code...]

call someTask {
    input:
        samples=samples 
        # Me when I see this: "Oh, this task recieves an array of samples.",
        # but really it's just given an Int! I probably should just have called it
        # numberOfSamples.
}

In addition, these custom type names will make it harder for a third party to read you wdl files:

input {
    Fastq reads
    # Is is this a File, a String or a Struct?
    # Do I now have to look for a struct definition or a type alias?

    # vs

    File fastq
    # Ah, cool, a File representing a Fastq!
}

I also wonder how this will interact with structs, this looks like it might create some ambiguity in the syntax.

Just as a note, typing has many benefits without clearifying what a variable represents. It can speed up run/compile time, as you only need to check whether the type is approriate for a certain operation, not what the type actually is. I image it also simplifies how variables (and the underlying memory management) are handeled by the compiler/interpreter/execution-engine. It also lets other developers know what type should be used as parameter to function calls. This greatly reduces the chance of unexpected behavior and errors resulting from functions getting called with types the author of the function didn't expect. It allows IDEs to check and warn you of these kinds of mistakes and suggest functions that can be used for a given variable.
2reactions
patmageecommented, Oct 9, 2019

I think the question here is really what does the type alias hope to accomplish that proper naming of the variable would not? IMO if you are using the type to infer meaning of the varibale to the user then you are not naming your variables properly.

Its also worth noting that the way you are naming the File varibale (PathToFastq) gives the impression that the File is actually a String type and not a File type. To me the naming pattern you suggest actually makes it harder to read, since I would look for a separate reference to a File somewhere else and would not think that the PathToFastq actually refers to a file

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Type Aliases in TypeScript - DigitalOcean
In this tutorial, you will refactor code that uses string literals to include aliases. You will be able to use and understand TypeScript...
Read more >
TypeScript | Type Aliases - Codecademy
In TypeScript, type aliases create type definitions, using the `type` keyword and a name, that can be reused throughout the code.
Read more >
Is it OK to have type aliases for primitive types in TypeScript?
In many cases a plain type alias is not the correct choice because there's probably something else you should use instead. But it...
Read more >
What are type aliases and how to create it in Typescript
In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name...
Read more >
Documentation - Advanced Types - TypeScript
Type aliases create a new name for a type. Type aliases are sometimes similar to interfaces, but can name primitives, unions, tuples, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found