UNPKG

@definitelytyped/dts-critic

Version:

Checks a new .d.ts against the Javascript source and tells you what problems it has

56 lines (55 loc) 2.42 kB
export declare enum ErrorKind { /** Declaration needs to use `export =` to match the JavaScript module's behavior. */ NeedsExportEquals = "NeedsExportEquals", /** Declaration has a default export, but JavaScript module does not have a default export. */ NoDefaultExport = "NoDefaultExport", /** JavaScript exports property not found in declaration exports. */ JsPropertyNotInDts = "JsPropertyNotInDts", /** Declaration exports property not found in JavaScript exports. */ DtsPropertyNotInJs = "DtsPropertyNotInJs", /** JavaScript module has signatures, but declaration module does not. */ JsSignatureNotInDts = "JsSignatureNotInDts", /** Declaration module has signatures, but JavaScript module does not. */ DtsSignatureNotInJs = "DtsSignatureNotInJs" } export interface CheckOptions { errors: Map<ExportErrorKind, boolean>; } export type ExportErrorKind = ExportError["kind"]; export declare function dtsCritic(dtsPath: string, sourcePath: string, options?: CheckOptions, debug?: boolean): CriticError[]; export declare const defaultErrors: ExportErrorKind[]; /** * If dtsName is 'index' (as with DT) then look to the parent directory for the name. */ export declare function findDtsName(dtsPath: string): string; export declare function checkSource(name: string, dtsPath: string, srcPath: string, enabledErrors: Map<ExportErrorKind, boolean>, debug: boolean): ExportError[]; /** * Converts a package name from the name used in DT repository to the name used in npm. * @param baseName DT name of a package */ export declare function dtToNpmName(baseName: string): string; /** * @param error case-insensitive name of the error */ export declare function parseExportErrorKind(error: string): ExportErrorKind | undefined; export interface CriticError { kind: ErrorKind; message: string; position?: Position; } interface ExportEqualsError extends CriticError { kind: ErrorKind.NeedsExportEquals; } interface DefaultExportError extends CriticError { kind: ErrorKind.NoDefaultExport; position: Position; } interface MissingExport extends CriticError { kind: ErrorKind.JsPropertyNotInDts | ErrorKind.DtsPropertyNotInJs | ErrorKind.JsSignatureNotInDts | ErrorKind.DtsSignatureNotInJs; } interface Position { start: number; length: number; } type ExportError = ExportEqualsError | DefaultExportError | MissingExport; export {};