Skip to main content

LensStudio:TypeScript.ITypeScriptCompilationApi

Class

Plugin component interface for invoking TypeScript compilation on the current project or an isolated tsconfig.

Index

Example

const FileSystem = await import('LensStudio:FileSystem');
const { ITypeScriptCompilationApi } = await import('LensStudio:TypeScript');

const compiler = this.pluginSystem.findInterface(ITypeScriptCompilationApi) as ITypeScriptCompilationApi;
if (Editor.isNull(compiler)) {
console.log('Compilation API not available');
return;
}

const projectResult = await compiler.refreshProjectCompilation();
console.log(`Project compile: succeeded=${projectResult.succeeded} errors=${projectResult.errors.length}`);

const tmp = FileSystem.TempDir.create();
FileSystem.writeFile(
tmp.path.appended(new Editor.Path('a.ts')),
'const x: number = 1; export {};',
);
FileSystem.writeFile(
tmp.path.appended(new Editor.Path('tsconfig.json')),
JSON.stringify({
compilerOptions: { module: 'esnext', target: 'es2021', isolatedModules: true, outDir: 'out' },
include: ['a.ts'],
}),
);
const isolated = await compiler.runIsolatedCompilation(
tmp.path.appended(new Editor.Path('tsconfig.json')).toString(),
);
console.log(`Isolated compile: succeeded=${isolated.succeeded} errors=${isolated.errors.length}`);

Extends

Properties

interfaceId

static interfaceId: InterfaceId

Interface identifier for resolving the TypeScript compilation API via the plugin system.

Methods

getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

IPluginComponent.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

IPluginComponent.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

IPluginComponent.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

IPluginComponent.isSame


refreshProjectCompilation()

refreshProjectCompilation(): Promise<TypeScriptCompilationResult>

Recompiles the current project TypeScript and resolves with the resulting compilation result.

Returns

Promise<TypeScriptCompilationResult>


runIsolatedCompilation()

runIsolatedCompilation(tsconfigPath): Promise<TypeScriptCompilationResult>

Compiles the project at the given tsconfig path in isolation and resolves with the resulting compilation result.

Parameters

ParameterType
tsconfigPathstring

Returns

Promise<TypeScriptCompilationResult>