Wednesday, December 27, 2017

I can't find it, but I know elsewhere on this blog I describe any in TypeScript as like dynamic in C# and Object in contrast like object in C#.

https://stackoverflow.com/questions/18961203/typescript-any-vs-object This has a better description partway down. It contrasts these three:

  1. var a: any;
  2. var b: Object;
  3. var c: {};

Alright, the third of these is basically just an extension of the second, and if you do .Whatever(); off of the second and third items TypeScript's compiler will lose it because there is an interface, if you will (per diegovilar and Retsam), associated with Object that makes it obvious that there is no .Whatever(); In contrast, the first item will allow for .Whatever(); to be called upon it without a compiler error. Any error, should there be one, will happen at runtime. There is no "interface" at the any and the compiler doesn't impose itself.

No comments:

Post a Comment