Skip to content

Instantly share code, notes, and snippets.

@aquapi
Created November 29, 2025 05:52
Show Gist options
  • Select an option

  • Save aquapi/4af7e99cc23ffe6626587c1eb6093e91 to your computer and use it in GitHub Desktop.

Select an option

Save aquapi/4af7e99cc23ffe6626587c1eb6093e91 to your computer and use it in GitHub Desktop.
declare const _: unique symbol;
export interface Redacted<out T> extends Symbol {
[_]: T
}
const redactMap = new WeakMap();
export const init = <const T>(val: T): Redacted<T> => {
const sym = Symbol('<redacted>');
redactMap.set(sym, val);
return sym as any as Redacted<T>;
}
export const value = <const T>(redacted: Redacted<T>): T => redactMap.get(redacted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment