-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

The JavaScript JSON Cookbook
By :

This last recipe is more of a tip than a recipe; if you've got some JSON you developed using another programming language or by hand, you can easily create a TypeScript interface for objects to contain the JSON by using Timmy Kokke's json2ts website.
Simply go to http://json2ts.com and paste your JSON in the box that appears, and click on the generate TypeScript button. You'll be rewarded with a second text-box that appears and shows you the definition of the TypeScript interface, which you can save as its own file and include in your TypeScript applications.
The following figure shows a simple example:
You can save this typescript as its own file, a definition
file, with the suffix .d.ts
, and then include the module with your TypeScript using the import
keyword, like this:
import module = require('module');
Change the font size
Change margin width
Change background colour