Solution: TypeScript Basics
Review the solutions to the challenges discussed in the previous lesson.
Solution: Convert JavaScript to TypeScript
Both solutions involve using the any
type.
-
In Solution # 1, the variable
item1
is explicitly given a type ofany
, allowing it to accept any kind of value. -
In Solution # 2, the type assertion
<any>
is used to indicate that the object literal should be treated asany
type.
By using the any
type, we can bypass type checking and assign the object literal with only the id
property to the item1
variable, resolving the type mismatch error.
Get hands-on with 1400+ tech skills courses.