Created
November 28, 2019 09:07
-
-
Save wmadden/3c300a94bd1cea0da396e9d78dc3a9e1 to your computer and use it in GitHub Desktop.
better-return-type-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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