I have a type SecretString which can contain any kind of sensitive information that I may handle on my server but which I don't want to accidentally log out. It's a branded string type:
type SecretString = string & {__brand: "secret"}
My logging function takes a string and an object (any, currently) which can contain whatever additional information might be necessary. Is there a way for me to express that second parameter as a type that can be an arbitrary object but will complain if a SecretString is present? Nested checking would be great but I would be happy with first level.
As the SecretString works just like a string, it typically comes from a function like this one:
function decryptString(encryptedString: EncryptedString): SecretString {
// ...
}
So this is an example of a scenario where I would like an error message:
const keys = decryptString(encryptedKeys);
logger.info('This should not compile!', {
valueThatIsOk: 'this is ok',
valueThatShouldFail: keys
});