TypeScript Support
abstract
Sahi allows scripts to be written in TypeScript. TypeScript .ts files need to be first compiled to JS and then executed via Sahi.
warning
This is an advanced customization and should be used only when you absolutely need to use TypeScript. Sahi's editor etc. do not have native support for TypeScript.
Pre-requisites
- Node.js must be installed in the system.
- TypeScript must be installed in the system.
Building TypeScript
- Copy
<SahiPro>/userdata/scripts/sahitests/typescript/sahi_apis.ts
file in your TypeScript workspace. - Create
tsconfig.json
in your workspace, if not exist and put the following contents{ "compileOnSave": true, "compilerOptions": { "target": "es3", "outDir": "<SahiPro>/userdata/scripts/sahitests/typescript/out" } }
infoNOTE: Replace<SahiPro>
with the Sahi Pro installation directory. Target should bees3
- Open the TypeScript workspace in MS Code and build the project.
Or,Go to: Tasks -> Run Build Task -> tsc:build
Open a command prompt/bash, cd to TypeScript workspace and runtsc
. - It will build the TypeScript workspace and create JavaScript files in
<SahiPro>/userdata/scripts/sahitests/typescript/out
directory. - Open the JavaScript files in Sahi Pro Editor and run the script.