title: Typescript: "If this was intentional, convert the expression to 'unknown' first."
body: <p>When casting a type to another type, the Typescript compiler often tells me to cast to unknown first. I never understand the reason behind this. Could someone please explain why this is necessary?</p>
  <p>Here is an example:</p>
  <pre><code>// An Animal is a living thing.
  type Animal = { livingThing: true }
  
  // A Dog or Cat type is a subtype of an Animal type.
  type Dog = { livingThing: true, woof: true, }
  type Cat = { livingThing: true, meow: true, }
  
  
  
  // We have a cat and a dog: meow and woof.
  const meow:Cat = { livingThing: true, meow: true }
  const woof:Dog = { livingThing: true, woof: true }
  
  // We have a living thing.
  const someLivingThing:Animal = { livingThing: true }
  
  // Let us assert that a living thing must be a cat.
  const isACat:Cat = someLivingThing
  //    ^^^^^^(type error 1)
  
  // Trust me, this living thing is a cat. (note 1)
  const isACat_trustMe:Cat = someLivingThing as Cat
  
  
  // A dog pretends to be a cat but fails.
  const dog_pretend_cat_failed:Cat = woof as Cat
                                  // ^^^^^^^^^^^(type error 2)
  
  // A dog successfully pretending to be a cat.
  const dog_pretend_cat_succeed:Cat = woof as unknown as Cat
  
  
  /*
  ---------
  note 1:
  Type casting in action.
  
  
  type error 1:
  [tsserver 2741] [E] Property 'meow' is missing in type 'Animal' but required in type 'Cat'.
  
  type error 2:
  [tsserver 2352] Conversion of type 'Dog' to type 'Cat'
                  may be a mistake because neither type sufficiently
                  overlaps with the other. If this was intentional,
                  convert the expression to 'unknown' first. [E]
  */ 
  
  </code></pre>
  <p>Here is the <a href="https://www.typescriptlang.org/play?#code/PTAEEEDsMhLBbAhgG1LAzqRpmwG6yQDmoALgBaFEB0AUKQJ4AOApjAiqALygDeO%20KgBVKxAFxkATgFc2AX1q0QEUABEA9iXWTQAYUSkyzNhiyh00gEaNWodQDMs0KB1Q2Wdd2s3c%20AgsQiVBKkMiwANKAA7uoOIWGRCl76hjz8uAFEQeJSspHwLOpR8XmgCopKYADqbOSIeGzYAMYGTgAmZm2aEgVF7dGx9nRN6pDohr3FKb7pgoGiRCURoJNLZbQjY4YxcRokaf7CC0uRO-Zr5co1oHUNZhlUZAvDo%20Pm6gUAMnNZxy5IqAOD3mwVy8kUyk%20LEM0kwiHQ6BYkkMFFa2GBJAoj3gsMMlkaoBapBeWzQ6HAKTE0x46A%20LG%20mWyREqoFZoAAepyuQAKLxIyTaUAARgAlBCwEIZG8CpEsZgMU9HqZmgZqKBuZB1KQ2KKNq9DBgKQYAPqhXEAWRYVNaNLpDKOj3hegMFWU4FAXRITEk0JYkDamFI6lA%20LMRJD0kM9kQsGQ6BJb09xu9vv9xqJxujsZYbWtqQGDiwmBStDZZfLFcrleUXNrtd5xlA-MFACYxSz3Z7zNImk0WAj7NJkMgGKAU9r-Y8gyGCUSE4Yk%20O-W10yaLL2WDm874zkXQNJIABrTVRaBOksQgBUtAAtHf7-faJrtcKxLQhI2WuMlWemqRYKMdCKHykgCjoQpvgA2qQCJIg0OgtgA7AALEKAC6oCQQAohhAAKAqsMio4AOSTMRZIrBg6A-kYtjEf8KDkZYkagD6ACO0iwD6HSELRbDESkxFASBYGgC2UEwYikjwWJADMACsLYYboozwdRox2I4XjEXs5HTtpgmllWlZIKOobYPAGCkIgh5sPiLSwmwkAsLAFBInx3b2PYsBNLAfqkCORnGeW6jwcgiBMJgUSueQTxsFq5BImqACSWmUFFTqEBO-6jCg4RBcFbKbPBKKJU2AAeKYIgB0DTsRB7HkUkDkd5kjjGq2FobQl7AEAA" rel="nofollow noreferrer">link</a> of this piece of code to Typescript playground</p>