Skip to content

Commit 3ef5c06

Browse files
fix typescript
1 parent 880b209 commit 3ef5c06

File tree

3 files changed

+52
-36
lines changed

3 files changed

+52
-36
lines changed

tests/DocsParser.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import { DocsParser } from '../src/DocsParser.js';
5+
import type { ModuleDocumentationContainer } from '../src/ParsedDocumentation.js';
56

67
describe('DocsParser', () => {
78
let tempDir: string;
@@ -66,8 +67,8 @@ A \`string\` property that indicates the current application's name.
6667
expect(appModule).toBeDefined();
6768
expect(appModule?.type).toBe('Module');
6869
// Just check that process information is present
69-
expect(appModule?.process).toBeDefined();
70-
expect(appModule?.process?.main).toBe(true);
70+
expect((appModule as ModuleDocumentationContainer).process).toBeDefined();
71+
expect((appModule as ModuleDocumentationContainer).process.main).toBe(true);
7172
expect(appModule?.description).toContain('Control your application');
7273

7374
if (appModule && appModule.type === 'Module') {
@@ -328,8 +329,8 @@ Expose API to renderer.
328329
const contextBridgeModule = result.find((m) => m.name === 'contextBridge');
329330

330331
// Just verify process information is parsed
331-
expect(appModule?.process).toBeDefined();
332-
expect(contextBridgeModule?.process).toBeDefined();
332+
expect((appModule as ModuleDocumentationContainer).process).toBeDefined();
333+
expect((contextBridgeModule as ModuleDocumentationContainer).process).toBeDefined();
333334
});
334335
});
335336

tests/index.spec.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22
import fs from 'node:fs';
33
import path from 'node:path';
4-
import { parseDocs } from '../src/index';
4+
import { parseDocs } from '../src/index.js';
5+
import type {
6+
ModuleDocumentationContainer,
7+
ClassDocumentationContainer,
8+
StructureDocumentationContainer,
9+
ElementDocumentationContainer,
10+
} from '../src/ParsedDocumentation.js';
11+
12+
type ParsedItem = ModuleDocumentationContainer | ClassDocumentationContainer | StructureDocumentationContainer | ElementDocumentationContainer;
513

614
describe('index (public API)', () => {
715
let tempDir: string;
@@ -48,7 +56,7 @@ Quit the application.
4856
expect(Array.isArray(result)).toBe(true);
4957
expect(result.length).toBeGreaterThan(0);
5058

51-
const appModule = result.find((m) => m.name === 'app');
59+
const appModule = result.find((m: ParsedItem) => m.name === 'app');
5260
expect(appModule).toBeDefined();
5361
});
5462

@@ -76,7 +84,7 @@ Test method.
7684
});
7785

7886
// In single package mode, classes are not nested in modules
79-
const testClass = result.find((item) => item.name === 'TestClass');
87+
const testClass = result.find((item: ParsedItem) => item.name === 'TestClass');
8088
expect(testClass).toBeDefined();
8189
expect(testClass?.type).toBe('Class');
8290
});
@@ -114,7 +122,7 @@ Test method.
114122
});
115123

116124
// In multi package mode, classes are nested in modules
117-
const testModule = result.find((item) => item.name === 'TestModule');
125+
const testModule = result.find((item: ParsedItem) => item.name === 'TestModule');
118126
expect(testModule).toBeDefined();
119127
expect(testModule?.type).toBe('Module');
120128

@@ -140,7 +148,7 @@ Test method.
140148
moduleVersion: '1.0.0',
141149
});
142150

143-
const pointStructure = result.find((s) => s.name === 'Point');
151+
const pointStructure = result.find((s: ParsedItem) => s.name === 'Point');
144152
expect(pointStructure).toBeDefined();
145153
expect(pointStructure?.type).toBe('Structure');
146154
});
@@ -175,8 +183,8 @@ Quit the app.
175183
moduleVersion: '1.0.0',
176184
});
177185

178-
expect(result.some((item) => item.name === 'app')).toBe(true);
179-
expect(result.some((item) => item.name === 'Options')).toBe(true);
186+
expect(result.some((item: ParsedItem) => item.name === 'app')).toBe(true);
187+
expect(result.some((item: ParsedItem) => item.name === 'Options')).toBe(true);
180188
});
181189

182190
it('should use README when useReadme is true', async () => {
@@ -203,7 +211,7 @@ Initialize the package.
203211
expect(result).toBeDefined();
204212
expect(result.length).toBeGreaterThan(0);
205213

206-
const packageModule = result.find((m) => m.name === 'MyPackage');
214+
const packageModule = result.find((m: ParsedItem) => m.name === 'MyPackage');
207215
expect(packageModule).toBeDefined();
208216
});
209217

@@ -293,9 +301,9 @@ Quit the app.
293301
});
294302

295303
expect(result.length).toBeGreaterThanOrEqual(3);
296-
expect(result.some((item) => item.name === 'app')).toBe(true);
297-
expect(result.some((item) => item.name === 'BrowserWindow')).toBe(true);
298-
expect(result.some((item) => item.name === 'dialog')).toBe(true);
304+
expect(result.some((item: ParsedItem) => item.name === 'app')).toBe(true);
305+
expect(result.some((item: ParsedItem) => item.name === 'BrowserWindow')).toBe(true);
306+
expect(result.some((item: ParsedItem) => item.name === 'dialog')).toBe(true);
299307
});
300308
});
301309

@@ -363,7 +371,7 @@ Quit the app.
363371

364372
// Should have parsed both api files and structures
365373
expect(result.length).toBeGreaterThanOrEqual(1);
366-
expect(result.some((item) => item.type === 'Module' || item.type === 'Structure')).toBe(true);
374+
expect(result.some((item: ParsedItem) => item.type === 'Module' || item.type === 'Structure')).toBe(true);
367375
});
368376
});
369377
});

tests/markdown-helpers.spec.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ import {
2727
getTopLevelOrderedTypes,
2828
convertListToTypedKeys,
2929
} from '../src/markdown-helpers.js';
30-
import { DocumentationTag } from '../src/ParsedDocumentation.js';
30+
import {
31+
DocumentationTag,
32+
type DetailedFunctionType,
33+
type DetailedObjectType,
34+
type DetailedStringType,
35+
type DetailedEventType,
36+
type DetailedEventReferenceType,
37+
} from '../src/ParsedDocumentation.js';
3138

3239
const getTokens = (md: string) => {
3340
const markdown = new MarkdownIt({ html: true });
@@ -1314,8 +1321,8 @@ Second level methods.`;
13141321
it('should handle Function type without subTypedKeys', () => {
13151322
const result = rawTypeToTypeInformation('Function', '', null);
13161323
expect(result.type).toBe('Function');
1317-
expect(result.parameters).toEqual([]);
1318-
expect(result.returns).toBeNull();
1324+
expect((result as DetailedFunctionType).parameters).toEqual([]);
1325+
expect((result as DetailedFunctionType).returns).toBeNull();
13191326
});
13201327

13211328
it('should handle Function type with subTypedKeys', () => {
@@ -1329,16 +1336,16 @@ Second level methods.`;
13291336

13301337
const result = rawTypeToTypeInformation('Function', '', typedKeys);
13311338
expect(result.type).toBe('Function');
1332-
expect(result.parameters).toHaveLength(2);
1333-
expect(result.parameters![0].name).toBe('callback');
1334-
expect(result.parameters![1].name).toBe('event');
1335-
expect(result.returns).toBeNull();
1339+
expect((result as DetailedFunctionType).parameters).toHaveLength(2);
1340+
expect((result as DetailedFunctionType).parameters[0].name).toBe('callback');
1341+
expect((result as DetailedFunctionType).parameters[1].name).toBe('event');
1342+
expect((result as DetailedFunctionType).returns).toBeNull();
13361343
});
13371344

13381345
it('should handle Object type without subTypedKeys', () => {
13391346
const result = rawTypeToTypeInformation('Object', '', null);
13401347
expect(result.type).toBe('Object');
1341-
expect(result.properties).toEqual([]);
1348+
expect((result as DetailedObjectType).properties).toEqual([]);
13421349
});
13431350

13441351
it('should handle String type with subTypedKeys', () => {
@@ -1352,15 +1359,15 @@ Second level methods.`;
13521359

13531360
const result = rawTypeToTypeInformation('String', '', typedKeys);
13541361
expect(result.type).toBe('String');
1355-
expect(result.possibleValues).toHaveLength(2);
1356-
expect(result.possibleValues![0].value).toBe('option1');
1362+
expect((result as DetailedStringType).possibleValues).toHaveLength(2);
1363+
expect((result as DetailedStringType).possibleValues![0].value).toBe('option1');
13571364
});
13581365

13591366
it('should handle Event<> with inner type', () => {
13601367
const result = rawTypeToTypeInformation('Event<CustomEvent>', '', null);
13611368
expect(result.type).toBe('Event');
1362-
expect(result.eventPropertiesReference).toBeDefined();
1363-
expect(result.eventPropertiesReference!.type).toBe('CustomEvent');
1369+
expect((result as DetailedEventReferenceType).eventPropertiesReference).toBeDefined();
1370+
expect((result as DetailedEventReferenceType).eventPropertiesReference.type).toBe('CustomEvent');
13641371
});
13651372

13661373
it('should throw on Event<> with both inner type and parameter list', () => {
@@ -1394,15 +1401,15 @@ Second level methods.`;
13941401

13951402
const result = rawTypeToTypeInformation('Event<>', '', typedKeys);
13961403
expect(result.type).toBe('Event');
1397-
expect(result.eventProperties).toHaveLength(1);
1398-
expect(result.eventProperties![0].name).toBe('detail');
1404+
expect((result as DetailedEventType).eventProperties).toHaveLength(1);
1405+
expect((result as DetailedEventType).eventProperties[0].name).toBe('detail');
13991406
});
14001407

14011408
it('should handle Function<> with generic types', () => {
14021409
const result = rawTypeToTypeInformation('Function<String, Number, Boolean>', '', null);
14031410
expect(result.type).toBe('Function');
1404-
expect(result.parameters).toHaveLength(2);
1405-
expect(result.returns!.type).toBe('Boolean');
1411+
expect((result as DetailedFunctionType).parameters).toHaveLength(2);
1412+
expect((result as DetailedFunctionType).returns!.type).toBe('Boolean');
14061413
});
14071414

14081415
it('should handle Function<> without generic params falling back to subTypedKeys', () => {
@@ -1413,9 +1420,9 @@ Second level methods.`;
14131420

14141421
const result = rawTypeToTypeInformation('Function<Boolean>', '', typedKeys);
14151422
expect(result.type).toBe('Function');
1416-
expect(result.parameters).toHaveLength(1);
1417-
expect(result.parameters![0].name).toBe('arg1');
1418-
expect(result.returns!.type).toBe('Boolean');
1423+
expect((result as DetailedFunctionType).parameters).toHaveLength(1);
1424+
expect((result as DetailedFunctionType).parameters[0].name).toBe('arg1');
1425+
expect((result as DetailedFunctionType).returns!.type).toBe('Boolean');
14191426
});
14201427

14211428
it('should throw on generic type without inner types', () => {
@@ -1434,7 +1441,7 @@ Second level methods.`;
14341441
expect(result.type).toBe('Promise');
14351442
expect(result.innerTypes).toHaveLength(1);
14361443
expect(result.innerTypes![0].type).toBe('Object');
1437-
expect(result.innerTypes![0].properties).toHaveLength(1);
1444+
expect((result.innerTypes![0] as DetailedObjectType).properties).toHaveLength(1);
14381445
});
14391446
});
14401447

0 commit comments

Comments
 (0)