Skip to content

Instantly share code, notes, and snippets.

@phpnode
Created April 6, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpnode/69b2062c174a04742b18f19f442133a1 to your computer and use it in GitHub Desktop.
Save phpnode/69b2062c174a04742b18f19f442133a1 to your computer and use it in GitHub Desktop.
type Linkable = {
name: string,
profileURL: string
};
function bigOldObject () {
return {
id: 1,
name: 'foo',
email: 'foo@bar.com',
avatarURL: '/wat.jpg',
profileURL: '/user/1'
};
}
function makeLink () {
// Here we're explicitly saying that we only depend
// on the 'Linkable' properties, despite the function
// returning a larger object.
const subject: Linkable = bigOldObject();
console.log(subject.id); // a flow error
return <a href={subject.profileURL}>{subject.name}</a>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment