With TypeScript
In this guide, you'll learn how to use LlamaIndex with TypeScript
LlamaIndex.TS is written in TypeScript and designed to be used in TypeScript projects.
We put a lot of work on strong typing to make sure you have a great typing experience with code completion such as:
Enable TypeScript
Make sure to set moduleResolution in your tsconfig.json
file:
We recommend using bundler
or nodenext
, but due to popularity of node
, we still added support for it, but with import path limitations.
So you may encounter type errors when importing sub paths from the llamaindex
package like:
The simplest way to fix this without changing moduleResolution
is to import directly from llamaindex
:
Enable AsyncIterable for Web Stream
API
Some modules uses Web Stream
API like ReadableStream
and WritableStream
, you need to enable DOM.AsyncIterable
in your tsconfig.json
.
Run TypeScript Script in Node.js
We recommend to use tsx to run TypeScript script in Node.js.