Remove @ts-ignores.

Co-authored-by: Yash Singh <saiansh2525@gmail.com>
This commit is contained in:
Sidharth Vinod 2022-08-25 21:53:36 +05:30
parent 84148d4891
commit a3dfc4c0e8
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
8 changed files with 32 additions and 18 deletions

View File

@ -2,6 +2,7 @@ import * as configApi from './config';
import { log } from './logger';
import { getDiagram } from './diagram-api/diagramAPI';
import { detectType } from './diagram-api/detectType';
import { isDetailedError } from './utils';
export class Diagram {
type = 'graph';
parser;
@ -42,11 +43,9 @@ export class Diagram {
// Is this the correct way to access mermiad's parseError()
// method ? (or global.mermaid.parseError()) ?
if (parseError) {
// @ts-ignore
if (error.str != undefined) {
if (isDetailedError(error)) {
// handle case where error string and hash were
// wrapped in object like`const error = { str, hash };`
// @ts-ignore
parseError(error.str, error.hash);
} else {
// assume it is just error string and pass it on

View File

@ -13,11 +13,11 @@ let currentConfig: MermaidConfig = assignWithDepth({}, defaultConfig);
export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: any[]) => {
// start with config being the siteConfig
let cfg = assignWithDepth({}, siteCfg);
let cfg: MermaidConfig = assignWithDepth({}, siteCfg);
// let sCfg = assignWithDepth(defaultConfig, siteConfigDelta);
// Join directives
let sumOfDirectives = {};
let sumOfDirectives: MermaidConfig = {};
for (let i = 0; i < _directives.length; i++) {
const d = _directives[i];
sanitize(d);
@ -28,16 +28,15 @@ export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: any[])
cfg = assignWithDepth(cfg, sumOfDirectives);
// @ts-ignore
if (sumOfDirectives.theme && theme[sumOfDirectives.theme]) {
if (sumOfDirectives.theme && sumOfDirectives.theme in theme) {
const tmpConfigFromInitialize = assignWithDepth({}, configFromInitialize);
const themeVariables = assignWithDepth(
tmpConfigFromInitialize.themeVariables || {},
// @ts-ignore
sumOfDirectives.themeVariables
);
// @ts-ignore
cfg.themeVariables = theme[cfg.theme].getThemeVariables(themeVariables);
if (cfg.theme && cfg.theme in theme) {
cfg.themeVariables = theme[cfg.theme as keyof typeof theme].getThemeVariables(themeVariables);
}
}
currentConfig = cfg;

View File

@ -147,7 +147,7 @@ export const evaluate = (val: string | boolean): boolean =>
export const parseGenericTypes = function (text: string): string {
let cleanedText = text;
if (text.indexOf('~') != -1) {
if (text.indexOf('~') !== -1) {
cleanedText = cleanedText.replace('~', '<');
cleanedText = cleanedText.replace('~', '>');

View File

@ -1,5 +1,5 @@
import type { DiagramDetector } from '../../diagram-api/detectType';
export const gitGraphDetector: DiagramDetector = (txt) => {
return txt.match(/^\s*gitGraph/) != null;
return txt.match(/^\s*gitGraph/) !== null;
};

View File

@ -1,5 +1,5 @@
import { DiagramDetector } from '../../diagram-api/detectType';
export const mindmapDetector: DiagramDetector = (txt) => {
return txt.match(/^\s*mindmap/) != null;
return txt.match(/^\s*mindmap/) !== null;
};

View File

@ -1,6 +1,7 @@
/** Created by knut on 14-12-11. */
import { select } from 'd3';
import { log } from './logger';
import { getErrorMessage } from './utils';
let conf = {};
@ -89,8 +90,7 @@ export const draw = (id: string, mermaidVersion: string) => {
svg.attr('viewBox', '768 0 512 512');
} catch (e) {
log.error('Error while rendering info diagram');
// @ts-ignore
log.error(e.message);
log.error(getErrorMessage(e));
}
};

View File

@ -6,6 +6,7 @@ import { MermaidConfig } from './config.type';
import { log } from './logger';
import utils from './utils';
import { mermaidAPI } from './mermaidAPI';
import { isDetailedError } from './utils';
/**
* ## init
@ -39,10 +40,10 @@ const init = function (
initThrowsErrors(config, nodes, callback);
} catch (e) {
log.warn('Syntax Error rendering');
// @ts-ignore
log.warn(e.str);
if (isDetailedError(e)) {
log.warn(e.str);
}
if (mermaid.parseError) {
// @ts-ignore
mermaid.parseError(e);
}
}
@ -56,6 +57,7 @@ const initThrowsErrors = function (
const conf = mermaidAPI.getConfig();
// console.log('Starting rendering diagrams (init) - mermaid.init', conf);
if (config) {
// This is a legacy way of setting config. It is not documented and should be removed in the future.
// @ts-ignore
mermaid.sequenceConfig = config;
}

View File

@ -933,6 +933,20 @@ export const sanitizeCss = (str) => {
return str;
};
export interface DetailedError {
str: string;
hash: any;
}
export function isDetailedError(error: unknown): error is DetailedError {
return 'str' in error;
}
export function getErrorMessage(error: unknown): string {
if (error instanceof Error) return error.message;
return String(error);
}
export default {
assignWithDepth,
wrapLabel,