Identifier<T>

We can’t change the fact that the server is sending us String s, but we can change how those strings are represented locally using a wrapper and phantom types.

Usually when we define a generic type like Identifier<T> we also use that T elsewhere in the type, something like let value: T . However, when the T is only present as part of the declaration, it is called a phantom type.

What’s the point then? Why make something generic if we aren’t using the type? Well, we actually are using the type, just not in the usual way. Let’s take a look:

Updating our models to use this new type, they become:

and our function now becomes:

We have now made it impossible to incorrectly pass a String . We must provide an Identifier<Author> instead; otherwise, it will not compile even though they are all still String s underneath.