Let's consider the following simplified example:
type Reference<T extends {identifier: string}> = T['identifier']
In this type, TypeScript recognizes that it is a reference to an object where the identifier property is of type string. However, how can we make TypeScript treat two different identifiers as distinct strings?
For example, if we have the following incorrect assignment:
let blogRef: Reference<Blog> = ...
let userRef: Reference<User> = ...
// TypeScript allows this even though they are both strings:
blogRef = userRef
This is logically incorrect. Is there a way to enforce this as a compile-time check in TypeScript?