Let's say I have two or more type aliases, as such:
declare type A = string;
declare type B = string;
I have variables of these types, as well as functions that operate on them.
const a1: A = "example of a";
const b1: B = "example of b";
function withA(a: A){
console.log(a);
}
function withB(b: B){
console.log(b);
}
I would like the following code to error, but it does not:
withA(b1);
withB(a1);
How can I accomplish this? I will also need to be able to initialize the variables with a string (I'm assuming with a cast). However, once initialized I do not want the types to be "implicitly equivalent" and want to have the compiler forbid their interchangeable use.
I also would like to not have to use classes, as described here: TypeScript - specific string types