What are the differences between any vs Object in TypeScript?

31 Jan, 2020
TypeScript is an open-source programming language. It is a superset of JavaScript language. TypeScript is designed for the development of large applications.
any: It is a built-in data type in TypeScript which helps in describing the type of variable which we are unsure of while writing the code.Though the data type ‘any’ is useful it shouldn’t be used unnecessarily.
Syntax:var x: any; // This means x has no interface.

var x: any; // This means x has no interface.

Features:This data type can be used when there are no type definitions available.The ‘any’ datatype can be used to denote any JavaScript value.
This data type can be used when there are no type definitions available.
The ‘any’ datatype can be used to denote any JavaScript value.
Examples: Below codes illustrates any datatype in TypeScript:Code 1:<script>function add(one: any, two: any): number {  return one + two;}    console.log(add('Geeks', 'forgeeks'));            </script>                    Output:GeeksforgeeksCode 2:<script>function subtract(one: any, two: any): number {  return one - two;}   console.log(subtract(9, 5)); </script>Output:4
Code 1:<script>function add(one: any, two: any): number {  return one + two;}    console.log(add('Geeks', 'forgeeks'));            </script>                    
<script>function add(one: any, two: any): number {  return one + two;}    console.log(add('Geeks', 'forgeeks'));            </script>                    
Output:Geeksforgeeks
Geeksforgeeks
Code 2:<script>function subtract(one: any, two: any): number {  return one - two;}   console.log(subtract(9, 5)); </script>
<script>function subtract(one: any, two: any): number {  return one - two;}   console.log(subtract(9, 5)); </script>
Output:4
4
Object: It describes the functionality, object helps in representing the non-primitive types that is everything except number, string, boolean, big int, symbol, undefined and null. In TypeScript Object(O uppercased) is different from object(o lowercased).
Syntax:var y: Object; // This means y has Object interface.

var y: Object; // This means y has Object interface.

Features:Object exposes the functions and properties defined within the Object class.The object is a more specific way of declaration.
Object exposes the functions and properties defined within the Object class.
The object is a more specific way of declaration.
Examples: Below codes illustrates object in TypeScript:Code 1:<script>      Student={roll_no:11,name:"XYZ"}      document.write(Student.roll_no+" "+Student.name+" ");  </script>Output:11 XYZCode 2:<script>      emp={id:102,name:"ABC",salary:10000}      document.write(emp.id+" "+emp.name+" "+emp.salary);  </script> Output:102 ABC 10000
Code 1:<script>      Student={roll_no:11,name:"XYZ"}      document.write(Student.roll_no+" "+Student.name+" ");  </script>
<script>      Student={roll_no:11,name:"XYZ"}      document.write(Student.roll_no+" "+Student.name+" ");  </script>
Output:11 XYZ
11 XYZ
Code 2:<script>      emp={id:102,name:"ABC",salary:10000}      document.write(emp.id+" "+emp.name+" "+emp.salary);  </script> 
<script>      emp={id:102,name:"ABC",salary:10000}      document.write(emp.id+" "+emp.name+" "+emp.salary);  </script> 
Output:102 ABC 10000
102 ABC 10000
Difference between any and Object in TypeScript:
Picked
Technical Scripter 2019
JavaScript
Technical Scripter
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Roadmap to Learn JavaScript For Beginners
Difference Between PUT and PATCH Request
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?