Skip to content

Commit f1faac8

Browse files
Fix TS errors
1 parent bf045de commit f1faac8

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

src/languages/c.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default {
7373
/* OpenCL host API */
7474
const extensions = getOptionalLanguage('opencl-extensions');
7575
if (extensions) {
76-
insertBefore(base, 'keyword', extensions);
76+
insertBefore(base, 'keyword', /** @type {GrammarTokens} */ (extensions));
7777
delete base['type-opencl-host-cpp'];
7878
}
7979

@@ -104,4 +104,5 @@ export default {
104104

105105
/**
106106
* @typedef {import('../types.d.ts').GrammarToken} GrammarToken
107+
* @typedef {import('../types.d.ts').GrammarTokens} GrammarTokens
107108
*/

src/languages/cpp.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ export default {
103103
/* OpenCL host API */
104104
const extensions = getOptionalLanguage('opencl-extensions');
105105
if (extensions) {
106-
insertBefore(cpp, 'keyword', extensions);
106+
insertBefore(
107+
cpp,
108+
'keyword',
109+
/** @type {import('../types.d.ts').GrammarTokens} */ (extensions)
110+
);
107111
}
108112

109113
const baseInside = { ...cpp };

src/languages/css.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ export default {
8989

9090
const extras = getOptionalLanguage('css-extras');
9191
if (extras) {
92-
insertBefore(css, 'function', extras);
92+
insertBefore(
93+
css,
94+
'function',
95+
/** @type {import('../types.d.ts').GrammarTokens} */ (extras)
96+
);
9397
}
9498

9599
return css;

src/languages/hlsl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export default {
1212
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords
1313
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words
1414
'class-name': [
15-
...toArray(base['class-name']),
15+
...toArray(
16+
/** @type {import('../types.d.ts').GrammarTokens} */ (base)['class-name']
17+
),
1618
/\b(?:AppendStructuredBuffer|BlendState|Buffer|ByteAddressBuffer|CompileShader|ComputeShader|ConsumeStructuredBuffer|DepthStencilState|DepthStencilView|DomainShader|GeometryShader|Hullshader|InputPatch|LineStream|OutputPatch|PixelShader|PointStream|RWBuffer|RWByteAddressBuffer|RWStructuredBuffer|RWTexture(?:1D|1DArray|2D|2DArray|3D)|RasterizerState|RenderTargetView|SamplerComparisonState|SamplerState|StructuredBuffer|Texture(?:1D|1DArray|2D|2DArray|2DMS|2DMSArray|3D|Cube|CubeArray)|TriangleStream|VertexShader)\b/,
1719
],
1820
'keyword': [

src/languages/php.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export default {
352352

353353
const extras = getOptionalLanguage('php-extras');
354354
if (extras) {
355-
insertBefore(php, 'variable', extras);
355+
insertBefore(php, 'variable', /** @type {GrammarTokens} */ (extras));
356356
}
357357

358358
const embedded = embeddedIn('markup');
@@ -376,4 +376,5 @@ export default {
376376

377377
/**
378378
* @typedef {import('../types.d.ts').Grammar} Grammar
379+
* @typedef {import('../types.d.ts').GrammarTokens} GrammarTokens
379380
*/

src/languages/typescript.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export default {
88
require: javascript,
99
alias: 'ts',
1010
grammar ({ extend }) {
11-
/** @type {import('../types.d.ts').Grammar} */
12-
const typeInside = {};
11+
const typeInside = /** @type {import('../types.d.ts').Grammar} */ ({});
1312

1413
const typescript = extend('javascript', {
1514
'class-name': {
@@ -24,7 +23,7 @@ export default {
2423
});
2524

2625
typescript.keyword = [
27-
...toArray(typescript.keyword),
26+
...toArray(/** @type {import('../types.d.ts').GrammarTokens} */ (typescript).keyword),
2827

2928
// The keywords TypeScript adds to JavaScript
3029
/\b(?:abstract|declare|is|keyof|out|readonly|require|satisfies)\b/,

tests/core/registry.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('Registry', () => {
55
it('should resolve aliases', () => {
66
const { components } = new Prism();
77

8-
const grammar = {};
8+
const grammar = /** @type {Grammar} */ ({});
99
components.add({ id: 'a', alias: 'b', grammar });
1010

1111
assert.isTrue(components.has('a'));
@@ -21,7 +21,7 @@ describe('Registry', () => {
2121
it('should resolve aliases in optional dependencies', () => {
2222
const { components } = new Prism();
2323

24-
const grammar = {};
24+
const grammar = /** @type {Grammar} */ ({});
2525
components.add({ id: 'a', alias: 'b', grammar });
2626
components.add({
2727
id: 'c',
@@ -62,4 +62,7 @@ describe('Registry', () => {
6262
});
6363
});
6464

65-
/** @typedef {import('../../src/types.d.ts').GrammarOptions} GrammarOptions */
65+
/**
66+
* @typedef {import('../../src/types.d.ts').GrammarOptions} GrammarOptions
67+
* @typedef {import('../../src/types.d.ts').Grammar} Grammar
68+
*/

tests/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1313

1414
/* Language and Environment */
15-
"target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15+
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1616
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1717
// "jsx": "preserve", /* Specify what JSX code is generated. */
1818
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */

0 commit comments

Comments
 (0)