Skip to content

Instantly share code, notes, and snippets.

@carlrip
Created December 17, 2019 18:13
Show Gist options
  • Save carlrip/4270cbb8babd073c3e6f7849c51206cf to your computer and use it in GitHub Desktop.
Save carlrip/4270cbb8babd073c3e6f7849c51206cf to your computer and use it in GitHub Desktop.
The unknown type
const person: unknown = await getPerson(id);
if (isPersonWithAddress(person)) {
const postcode = person.address.postcode;
}
function isPersonWithAddress(person: any): person is Person {
return "address" in person && "postcode" in person.address;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment