Skip to content

Instantly share code, notes, and snippets.

@tswistak
Created January 16, 2019 10:26
Show Gist options
  • Save tswistak/03b2afacd8bdb42422336f1e3a8e6a4e to your computer and use it in GitHub Desktop.
Save tswistak/03b2afacd8bdb42422336f1e3a8e6a4e to your computer and use it in GitHub Desktop.
Avoiding any in TypeScript, listing 3
const dict2: { a?: string } & Record<string, number> = {};
dict2.a = 'a';
dict2.a = 1; // ERROR: 1 is not assignable to type string
dict2.b = 2;
dict2.b = 'b'; // ERROR: "b" is not assignable to type number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment