Olivier Refalo Olivier Refalo - 7 months ago 121
TypeScript Question

Typescript any vs Object

I am looking at typescript code and noticed that they use

interface Blablabla {

field: Object;


What is the benefit of using Object vs any, as in

interface Blablabla {

field: any;



Object is more restrictive than any. That is:

interface MyInterface {

    b: Object;

var foo = (a : MyInterface) => alert(a.b.nomethod());

Will not compile because Object does not have a nomethod() function. If you use any in the interface instead of Object it would compile.

So in short, any can be anything (you can call any method etc on it without compilation errors). If you explicitly use Object you will only be able to use the methods etc that are defined on the Object class.