90 render: (tokens, idx) => {
91 const m = tokens[idx].info.trim().match(/^details\s+(.*)$/);
92 if (tokens[idx].nesting === 1) {
93 return `<details class="custom-block details"><summary>${md.utils.escapeHtml(m![1])}</summary>\n`; 94 } else {
95 return "</details>\n";
96 }
79 render: (tokens, idx) => {
80 const m = tokens[idx].info.trim().match(/^info\s+(.*)$/);
81 if (tokens[idx].nesting === 1) {
82 return `<div class="custom-block info"><p class="custom-block-title">${md.utils.escapeHtml(m![1])}</p>\n`; 83 } else {
84 return "</div>\n";
85 }
68 render: (tokens, idx) => {
69 const m = tokens[idx].info.trim().match(/^danger\s+(.*)$/);
70 if (tokens[idx].nesting === 1) {
71 return `<div class="custom-block danger"><p class="custom-block-title">${md.utils.escapeHtml(m![1])}</p>\n`; 72 } else {
73 return "</div>\n";
74 }
57 render: (tokens, idx) => {
58 const m = tokens[idx].info.trim().match(/^warning\s+(.*)$/);
59 if (tokens[idx].nesting === 1) {
60 return `<div class="custom-block warning"><p class="custom-block-title">${md.utils.escapeHtml(m![1])}</p>\n`; 61 } else {
62 return "</div>\n";
63 }
46 render: (tokens, idx) => {
47 const m = tokens[idx].info.trim().match(/^tip\s+(.*)$/);
48 if (tokens[idx].nesting === 1) {
49 return `<div class="custom-block tip"><p class="custom-block-title">${md.utils.escapeHtml(m![1])}</p>\n`; 50 } else {
51 return "</div>\n";
52 }
Type assertion is explicitly telling the compiler that we want to treat the entity as a different type. However, if we add a type assertion for a variable which is automatically inferred with the same type already then it is unnecessary to define the type explicitly.
Using a type assertion that does not change the type of an expression is unnecessary and should be avoided for a cleaner code.
// Types of 'foo' and 'bar' are already inferred as 'number', explicit type assertion in unnecessary
let foo = 3 as number;
let bar = <number>3;
function foobar(x: number): number {
return x!; // Type of 'x' is 'number' and is not 'null' or 'undefined'. Non-null assertion is unnecessary
}
type NewType = number;
let baz = 3 as NewType
let qux = <NewType>3
const foo = [1, 2] as const; // Using 'as const' enforces the array to be readonly
function foobar(x: number | undefined): number {
return x!;
}