TypeScript will sometimes display the original Primitive Type rather than the Type Alias that you've set. By appending & {}
to your Type Alias, you can force TypeScript to display your Alias.
[00:00] When using type aliases, sometimes TypeScript would explicitly reflect the fact that a certain type alias is being used. But in some cases, such as here when we hover over the property of the employee object, type alias is gone since an alias basically reflects just the original primitive type. So it's basically the same. So in some cases, [00:20] it just doesn't show the fact. If you want to enforce TypeScript to highlight the fact that a type alias is being used, in case of primitive types, we can simply extend it with an empty object. In case of type compatibility, it doesn't change any rules. [00:40] But from now on, we can see that not only when displaying the whole object, but also when showing the type of the property, the fact of using type alias is reflected. Extending a primitive type with an empty object type doesn't change the compatibility rules because in JavaScript in the runtime [01:00] whenever we have a primitive number and for some reason we would like to treat it as if it was an object for instance 5.2 fixed, JavaScript is going to automatically wrap the primitive value into its object equivalent. So all in all, this is still going to be Numbuh though TypeScript is [01:20] just seeing it in a slightly different way.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!