Skip to content

Instantly share code, notes, and snippets.

@wmadden
Created November 28, 2019 09:07
Show Gist options
  • Save wmadden/3c300a94bd1cea0da396e9d78dc3a9e1 to your computer and use it in GitHub Desktop.
Save wmadden/3c300a94bd1cea0da396e9d78dc3a9e1 to your computer and use it in GitHub Desktop.
better-return-type-error.ts
type User = {
id: string;
name: string;
};
function getUser(): User {
return {
id: '123',
namee: 'Tom Hanks', // misspelled
// ^^^^^^^^^^^^^^^^^^
// Type '{ id: string; namee: string; }' is not assignable to type 'User'.
// Object literal may only specify known properties, but 'namee' does not exist in type 'User'. Did you mean to write 'name'?
};
}
console.log(getUser().name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment