0
const a:never[]=[]

const b:string[] = a // never[] CAN assign to string[]

const c=(d:never)=>{}
c(1) // number cant assign to never

const d =(e:string[])=>{}
d(a) // never[] CAN assign to string[]

const e = (f:never[])=>{}
e(b) // string[] cant assign to never[]

const f:never = 1 as never

const g:string = f // never CAN assign to string

console.log(g.toLowerCase()) // runtime error!!

playground

what is the typescript justification of able to assign never to other types?

it can cause runtime error as shown in the last line of the code

Acid Coder
  • 2,047
  • 15
  • 21
  • 1
    _The `never` type is a subtype of, and assignable to, **every** type; however, no type is a subtype of, or assignable to, `never` (except `never` itself). Even `any` isn’t assignable to `never`._ https://www.typescriptlang.org/docs/handbook/basic-types.html#never – Aleksey L. Sep 27 '20 at 12:53
  • What's the point of the examples above? – Aleksey L. Sep 27 '20 at 12:56

0 Answers0