diff --git a/README.md b/README.md index 691ac82..bcc4954 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ You can maually find the definition files in the `types` folder. If you have any doubt using this library please post a question on [stackoverflow](http://stackoverflow.com/questions/ask?tags=treemodel) tagged with `treemodel`. -## API Reference +## JavaScript API Reference ### Create a new TreeModel @@ -159,6 +159,26 @@ node.walk([options], action, [context]) These functions can also take, as the last parameter, the *context* on which the action will be called. +## Typescript Refrence + +You can maually find the definition files in the `types` folder. A quick summary, is rougly as follows: + +```ts +import * as TreeModel from "tree-model"; + +interface TestModel { + name: string; +} +const tree = new TreeModel({}); +const root = tree.parse({ name: 'a', children: [{ name: 'b' }, { name: 'c' }] }); +``` +It is also possible to type the input object (to parse) itself, instead of providing the generic type to `.parse`: + +```ts +const data : TreeModel.Model = { name: 'a', children: [{ name: 'b' }, { name: 'c' }] }; +const root = tree.parse(data); +``` + ## Contributing ### Setup