UNPKG

3.25 kBTypeScriptView Raw
1import { BaseError } from 'make-error';
2import * as TS from 'typescript';
3/**
4 * Common TypeScript interfaces between versions.
5 */
6export interface TSCommon {
7 version: typeof TS.version;
8 sys: typeof TS.sys;
9 ScriptSnapshot: typeof TS.ScriptSnapshot;
10 displayPartsToString: typeof TS.displayPartsToString;
11 createLanguageService: typeof TS.createLanguageService;
12 getDefaultLibFilePath: typeof TS.getDefaultLibFilePath;
13 getPreEmitDiagnostics: typeof TS.getPreEmitDiagnostics;
14 flattenDiagnosticMessageText: typeof TS.flattenDiagnosticMessageText;
15 transpileModule: typeof TS.transpileModule;
16 ModuleKind: typeof TS.ModuleKind;
17 ScriptTarget: typeof TS.ScriptTarget;
18 findConfigFile: typeof TS.findConfigFile;
19 readConfigFile: typeof TS.readConfigFile;
20 parseJsonConfigFileContent: typeof TS.parseJsonConfigFileContent;
21}
22/**
23 * Export the current version.
24 */
25export declare const VERSION: any;
26/**
27 * Registration options.
28 */
29export interface Options {
30 typeCheck?: boolean | null;
31 transpileOnly?: boolean | null;
32 cache?: boolean | null;
33 cacheDirectory?: string;
34 compiler?: string;
35 ignore?: string | string[];
36 project?: string;
37 skipIgnore?: boolean | null;
38 skipProject?: boolean | null;
39 compilerOptions?: object;
40 ignoreDiagnostics?: number | string | Array<number | string>;
41 readFile?: (path: string) => string | undefined;
42 fileExists?: (path: string) => boolean;
43 transformers?: TS.CustomTransformers;
44}
45/**
46 * Information retrieved from type info check.
47 */
48export interface TypeInfo {
49 name: string;
50 comment: string;
51}
52/**
53 * Default register options.
54 */
55export declare const DEFAULTS: Options;
56/**
57 * Split a string array of values.
58 */
59export declare function split(value: string | undefined): string[] | undefined;
60/**
61 * Parse a string as JSON.
62 */
63export declare function parse(value: string | undefined): object | undefined;
64/**
65 * Replace backslashes with forward slashes.
66 */
67export declare function normalizeSlashes(value: string): string;
68/**
69 * TypeScript diagnostics error.
70 */
71export declare class TSError extends BaseError {
72 diagnostics: TSDiagnostic[];
73 name: string;
74 constructor(diagnostics: TSDiagnostic[]);
75}
76/**
77 * Return type for registering `ts-node`.
78 */
79export interface Register {
80 cwd: string;
81 extensions: string[];
82 cachedir: string;
83 ts: TSCommon;
84 compile(code: string, fileName: string, lineOffset?: number): string;
85 getTypeInfo(code: string, fileName: string, position: number): TypeInfo;
86}
87/**
88 * Register TypeScript compiler.
89 */
90export declare function register(opts?: Options): Register;
91/**
92 * Format an array of diagnostics.
93 */
94export declare function formatDiagnostics(diagnostics: TS.Diagnostic[], cwd: string, ts: TSCommon, lineOffset: number): TSDiagnostic[];
95/**
96 * Internal diagnostic representation.
97 */
98export interface TSDiagnostic {
99 message: string;
100 code: number;
101}
102/**
103 * Format a diagnostic object into a string.
104 */
105export declare function formatDiagnostic(diagnostic: TS.Diagnostic, cwd: string, ts: TSCommon, lineOffset: number): TSDiagnostic;
106/**
107 * Stringify the `TSError` instance.
108 */
109export declare function printError(error: TSError): string;