Skip to content

Instantly share code, notes, and snippets.

@tswistak
Created January 16, 2019 10:35
Show Gist options
  • Save tswistak/3478f32cb1023ac6f1d93d036859dfce to your computer and use it in GitHub Desktop.
Save tswistak/3478f32cb1023ac6f1d93d036859dfce to your computer and use it in GitHub Desktop.
Avoiding any in TypeScript, listing 8
type E = { a: string; b: string; }
function withPick<K extends keyof E>(state: Pick<E, K>): void { return; }
function withPartial<E>(state: Partial<E>) { return; }
withPick({ a: null }); // 'null' is not assignable to type string
withPartial({ a: null }); // no error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment