Skip to content

Commit

Permalink
Merge pull request #1021 from bemisguided/chore/add-typescript-detail…
Browse files Browse the repository at this point in the history
…s-to-readme

chore: Add TypeScript Usage details to the README
  • Loading branch information
smwhr committed Aug 17, 2023
2 parents e2d55ad + 29c14a2 commit 35a1ca9
Showing 1 changed file with 38 additions and 6 deletions.
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)
- [](#)
- [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

0 comments on commit 35a1ca9

Please sign in to comment.