Learn R Programming

jsutils (version 0.2.0)

typescript: Transpile TypeScript code to JavaScript

Description

This function uses the TypeScript compiler to transpile TypeScript code into JavaScript. Note that the first time this function is called, it will load the TypeScript library into the JavaScript context, which may take a few seconds. Subsequent calls will be faster.

Usage

typescript(input, options = NULL)

Value

A list containing the transpiled JavaScript code and any diagnostics.

Arguments

input

Either a path to a file or a character string containing the TypeScript code to be transpiled.

options

A list of options to pass to the TypeScript transpiler. See the TypeScript documentation for available options.

Examples

Run this code
ts_code <- "const greet = (name: string): string => `Hello, ${name}!`;"
typescript(ts_code, list(compilerOptions = list(target = "ES5")))

Run the code above in your browser using DataLab