Last date modified: 2026-Jul-14
Using TypeScript
You can implement Relativity extension scripts in TypeScript, which is a typed superset of JavaScript. It compiles to plain JavaScript that runs in the browser. For more information, see TypeScript.
This page contains the following information:
- Benefits of TypeScript
- Consuming the Review API package
- Version pinning
- Updating the reviewapi version
Benefits of TypeScript
Implementing extension scripts in TypeScript has the following benefits:
- Provides IntelliSense for the Review API interfaces, methods, enums, and other programming entities in editors such as Visual Studio Code. You can explore the
reviewapipackage in the editor itself without needing to search through the API documentation. - Provides compile-time feedback when using the API incorrectly, such as missing required arguments or passing the wrong types. You can catch errors before the extension runs.
Consuming the Review API package
The Review API is available as an npm package. Install it as a dev dependency — reviewapi is a types-only package and has no runtime footprint.
Install the Review API package
npm install --save-dev reviewapi
Import from the Review API package
Because reviewapi has no JavaScript exports, all imports must use import type — including enums. Enum types in reviewapi are declare enum ambient declarations; the underlying string values are provided by the viewer at runtime. When a typed function parameter requires an enum value, cast the string using as unknown as EnumType:
import type { IExtensionParameters, IExtensionConfig, IReviewInterfaceApi, TextSearchMode } from 'reviewapi';
// Cast string to enum type — the string value matches the enum member at runtime
const mode = 'literal' as unknown as TextSearchMode;
export default function(parameters: IExtensionParameters): IExtensionConfig {
return {
id: 'relativity.exampleextension',
name: 'TypeScript Example',
lifecycle: {
apiready: (api: IReviewInterfaceApi) => {
console.log('API ready.');
},
},
};
}
For more information, see Modules on the TypeScript web site.
Version pinning
A corresponding version of the reviewapi npm package exists for each release of the Relativity Review application. We recommend using the matching version to ensure the type definitions align with the version you are targeting.
The Relativity versioning follows the format: {major-version}.{minor-version}.{build-number}.
Note: A document viewer application with the version a.b.cd.ef matches a reviewapi npm package with the version a.b.cd00ef.
Updating the reviewapi version
-
Update the version in
package.json:Copy{
"devDependencies": {
"reviewapi": "5.0.120002"
}
} -
Run
npm installto pull the updated package. -
Build your extension to confirm it compiles without errors.