Type alias transparency

Type aliases are transparent, which means they are fully equivalent to the types of which they are aliases. For instance, this example’s notice returns true because MyType is an alias of the Integer type:

type MyModule::MyType = Integer
notice MyModule::MyType == Integer

Note: The internal types TypeReference and TypeAlias are never values in Puppet code.

Organizing type alias definitions

If you define type aliases inside of manifests that contain other Puppet code, you make it more difficult to find where and how they are defined. It’s easier to maintain and diagnose problems with type aliases by placing them into files within their own directory of your Puppet module.

Store type aliases as .pp files in your module’s types directory, which is a top-level directory and sibling of the manifests and lib directories. Define only one alias per file, and name the file after the type alias name converted to lowercase. For example, MyType is expected to be loaded from a file named mytype.pp.

Creating recursive types

You can create recursive types:

type MyModule::Tree = Array[Variant[Data, Tree]]

This Tree type alias is defined as a being built out of Arrays that contain Data, or a Tree:

[1,2 [3], [4, [5, 6], [[[[1,2,3]]]]]]

A recursive alias can refer to the alias being declared, or to other types.

This powerful mechanism allows you to define complex, descriptive type definitions instead of using the Any type.

Aliasing resource types

You can also create aliases to resource types.

type MyModule::MyFile = File

When defining an alias to a resource type, use its short form (such as File) instead of its long form (such as Resource[File]).