---
title: "compileTsSource(): function in Authoring, TypeShade API"
description: "compileTsSource, a function in Authoring. Compile a TypeScript source string through the TypeShade authoring pipeline."
url: https://typeshade.dev/api/compiletssource/
language: en
---

# `compileTsSource()`

Function in Authoring

Compile a TypeScript source string through the TypeShade authoring pipeline.

`import { compileTsSource } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function compileTsSource(
  source: string,
  options: CompileTsSourceOptions = {},
): CompileTsSourceResult
```

## Parameters

**`source` `string`**

**`options` optional `CompileTsSourceOptions`**

## Return value

`CompileTsSourceResult`

## Description

A source without the `"use typeshade"` directive returns `hasDirective: false`, no functions and one `MISSING_DIRECTIVE` error (unless `options.requireDirective` is `false`). `wgsl` is present only when the file lowered at least one function with no error diagnostic and `options.emit` is not `false`; a backend that throws on such a module is reported as a `BACKEND` error diagnostic and leaves `wgsl` undefined.

## Source

[`src/compiler/ts/source-file.ts`, line 186](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/source-file.ts#L186), at commit af54ddad5
