Type aliases are a convenient way to reflect intent in code without breaking existing behaviors.

Why Use Type Aliases

Aliases of interest

1
2
3
4
5
6
7
8
9
type TestId = string
type ProjectPath = string
type TargetFramework = string
type FullTestName = string
type TrxPath = string
type ConsoleOutput = string

type CodeBasedTestId = TestId
type ResultBasedTestId = TestId
1
2
let testLocationCache = Collections.Generic.Dictionary<string, LocationRecord>()
let testLocationCache = Collections.Generic.Dictionary<TestId, LocationRecord>()
  • Lots of function passing in F#. Easy to misunderstand without semantic names
    • Maybe give some examples from Ionide test explorer
    • maybe introduce by showing unaliased snippets and asking what they do
  • Much easier if you change type or refactor to value types for stronger guarantees
  • Talk about C#
    • Can’t really alias this way in C#. Aliases don’t work the same.
    • Establish that C# has the same problem (higher-order functions less common, but return parameters, for example still aren’t named)

Q: can type aliases be exported in C#?