Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript documentation, test or demo case #64

Open
ghost opened this issue Apr 5, 2019 · 3 comments
Open

Typescript documentation, test or demo case #64

ghost opened this issue Apr 5, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 5, 2019

Since about a year, your project has Typescript support using a types.d.ts file.

Now, I was wondering if you could provide some basic info on how to set up a simple tree with a few nodes. I'm no expert with Typescript myself so I was looking for some documentation, but I found very little. Perhaps that @bendtherules can chip in as he was part of the original implementation team.

@joaonuno
Copy link
Owner

joaonuno commented Apr 5, 2019

I know this is not what you're requesting, but check if this file helps in any way: https://github.com/joaonuno/tree-model-js/blob/master/types/tree-model-tests.ts

@bendtherules
Copy link

bendtherules commented Apr 5, 2019

Hey @Kevin-at-Navigram, thanks for opening the issue.

Would you prefer existing (and some more ??) readme examples to be also available in typescript?
I think the tests file linked above does that to some extent.

Just as a quickstart, this is how you create simple tree (copied from tests file):

interface TestModel {
    name: string;
}

const tree = new TreeModel({});

const root = tree.parse<TestModel>({ 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. That would be something like:

const data : TreeModel.Model<TestModel> = { name: 'a', children: [{ name: 'b' }, { name: 'c' }] };
const root = tree.parse(data);

@ghost ghost mentioned this issue Apr 5, 2019
@ghost
Copy link
Author

ghost commented Apr 5, 2019

He, I really appreciate this quick feedback. I did actually use the tests.ts file as a reference, but I thought it would be a nice addition to the website and documentation.

I've added it myself to the readme:
#65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants