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

chore: Add TypeScript Usage details to the README #1021

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ inkjs is fully compatible with the original version, has zero dependency and wor

## Table of content

- [Installation](#installation)
- [Quickstart in the browser](#quickstart)
- [Working with a JSON file](#working-with-a-json-file)
- [Using Node.js](#using-nodejs)
- [Differences with the C# API](#differences-with-the-c-api)
- [Using the js Compiler](#compiler)
- [](#)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode added indentation here, which seemed like a nice thing. Happy to remove though, if we want a cleaner PR.

- [Table of content](#table-of-content)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [Working with a JSON file](#working-with-a-json-file)
- [Using node.js](#using-nodejs)
- [Loading inkjs](#loading-inkjs)
- [Loading a json file](#loading-a-json-file)
- [Starting a story](#starting-a-story)
- [Differences with the C# API](#differences-with-the-c-api)
- [Getting and setting ink variables](#getting-and-setting-ink-variables)
- [Getting the output text when calling `EvaluateFunction`](#getting-the-output-text-when-calling-evaluatefunction)
- [Using TypeScript](#using-typescript)
- [Compiler](#compiler)
- [inkjs-compiler.js](#inkjs-compilerjs)
- [online compiler](#online-compiler)
- [Differences with the C# Compiler](#differences-with-the-c-compiler)
- [Compatibility table](#compatibility-table)

## Installation

Expand Down Expand Up @@ -123,6 +135,26 @@ var result = EvaluateFunction('my_ink_function', ['arg1', 'arg2'], true);
// result.output is the text that was written to the output while the function was evaluated
```

## Using TypeScript

As this library is a port from C#, it requires a less standard way to assign the `Story` class, including all other classes, to a variable:

```ts
import { Story, Compiler } from 'inkjs';

let story: InstanceType<typeof Story>;
let compiler: InstanceType<typeof Compiler>;
```

Further, to minimize the verbose assignment, you can also create aliases in your project:

```ts
import { Story, Compiler } from 'inkjs';

export type InkStory = InstanceType<typeof Story>;
export type InkCompiler= InstanceType<typeof Compiler>;
```

## Compiler

### inkjs-compiler.js
Expand Down
Loading