Skip to content

Instantly share code, notes, and snippets.

@jamesseanwright
Created September 7, 2020 09:59
Show Gist options
  • Save jamesseanwright/2e419111c8bc4a2e4f1294698d25bc3d to your computer and use it in GitHub Desktop.
Save jamesseanwright/2e419111c8bc4a2e4f1294698d25bc3d to your computer and use it in GitHub Desktop.
Using the minus operator in TS mapped types
interface Person {
readonly name: string;
age?: number;
}
type WellFormedMutable<T> = {
-readonly[K in keyof T]-?: T[K];
};
const p: WellFormedMutable<Person> = {
name: 'Bob',
age: 21,
};
p.name = 'Roy';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment