InterviewSolution
| 1. |
What Is Typescript Definition Manager And Why Do You Need It? |
|
Answer» TypeScript Definition Manager (TSD) is a package manager to search and install TypeScript definition files directly from the community driven DefinitelyTyped repository. Let’s see with an example. Suppose, you want to USE some jQuery code in your .ts FILE. $(document).ready(function() { //Your jQuery code }); And now when you TRY to compile it using tsc, you will get compile time error Cannot FIND name “$”. That’s because TypeScript can’t understand what does “$” means. So somehow we need to inform TypeScript COMPILER that it belongs to jQuery. That’s where TSD comes into play. You can download jQuery Type Definition file and include it in your .ts file. First, install TSD. npm install tsd -g In your typescript directory, create a new typescript project by running: tsd init Then install the definition file for jquery. tsd query jquery --action install This will download and create a new directory containing your jquery definition file. The definition file ends with “.d.ts”. So now include it by updating your typescript file to point to the jquery definition. /// Now try to compile again and this time, js will be generated without any error. So TSD will help you to get type definition file for required framework. If you wish to use angular, then download angular type definition file. TypeScript Definition Manager (TSD) is a package manager to search and install TypeScript definition files directly from the community driven DefinitelyTyped repository. Let’s see with an example. Suppose, you want to use some jQuery code in your .ts file. $(document).ready(function() { //Your jQuery code }); And now when you try to compile it using tsc, you will get compile time error Cannot find name “$”. That’s because TypeScript can’t understand what does “$” means. So somehow we need to inform TypeScript compiler that it belongs to jQuery. That’s where TSD comes into play. You can download jQuery Type Definition file and include it in your .ts file. First, install TSD. npm install tsd -g In your typescript directory, create a new typescript project by running: tsd init Then install the definition file for jquery. tsd query jquery --action install This will download and create a new directory containing your jquery definition file. The definition file ends with “.d.ts”. So now include it by updating your typescript file to point to the jquery definition. /// Now try to compile again and this time, js will be generated without any error. So TSD will help you to get type definition file for required framework. If you wish to use angular, then download angular type definition file. |
|