diff --git a/src/languages/javascript.js b/src/languages/javascript.js index 65b60779a4..9f04452a0f 100644 --- a/src/languages/javascript.js +++ b/src/languages/javascript.js @@ -47,7 +47,13 @@ export default function(hljs) { nextChar === "<" || // the , gives away that this is not HTML // `` - nextChar === "," + nextChar === "," || + // TypeScript type assertion with array notation + // ``, ``, ``, etc. + nextChar === "[" || + // TypeScript optional type assertion + // ``, etc. + nextChar === "?" ) { response.ignoreMatch(); return; @@ -86,6 +92,13 @@ export default function(hljs) { return; } } + + // TypeScript type assertions with whitespace before brackets or question mark + // ``, ``, ``, `` + if ((m = afterMatch.match(/^\s*\[\]/)) || (m = afterMatch.match(/^\s+\?/))) { + response.ignoreMatch(); + return; + } } }; const KEYWORDS = {