0

In the following, when run, javascript has a runtime error. Why doesn't typescript see this as a type error?

const x : ((nv : any) => Map<string,string>) = function (nv : Map<string,string>) { return nv }

let a = "hi there"

let aMap = x(a)

console.log(aMap.get('foo'))

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAHjAXDAFCsA3JMCGYCeAlDALwB8MAsjgA4A80ATgJZgDmANE622cSTABmAVzDAozcKkzZq9buy5QW7PjADeMRgFMowxmBgyAvgChTAG125SMAEQALZjCgPtOu+auwcc23BQcQnNQSBArADoLEDZAuQi2XRQAckEQEGTCYKA

redfish64
  • 565
  • 3
  • 10
  • 1
    `any` is an escape clause from the type system. You've elected to *not* have TS verify types. Therefore, there is no type error. https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any – VLAZ Oct 31 '22 at 05:21

0 Answers0