refactor: reduce ignored type errors in AST conversion#22
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the AST conversion module to reduce ignored TypeScript errors by improving type safety and replacing // @ts-expect-error comments with proper type handling. The changes introduce type guards, utility functions, and better-typed interfaces to handle the gradual transformation from Typst AST to textlint AST without suppressing type errors.
Key changes include:
- Added comprehensive type imports and type guards for AST node validation
- Introduced utility functions for safe property access and type checking
- Replaced property deletion using
deletewithReflect.deleteProperty()for type safety
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/typstToTextlintAst.ts
Outdated
| const isTypstType = (type: string, pattern: string): boolean => { | ||
| return new RegExp(pattern).test(type); |
There was a problem hiding this comment.
Creating a new RegExp object on every call is inefficient. Consider using RegExp.prototype.test directly or caching compiled regex patterns if they're reused frequently.
| const isTypstType = (type: string, pattern: string): boolean => { | |
| return new RegExp(pattern).test(type); | |
| const isTypstType = (type: string, pattern: RegExp): boolean => { | |
| return pattern.test(type); |
src/typstToTextlintAst.ts
Outdated
| spread: false, | ||
| // @ts-expect-error | ||
| children: listItems, | ||
| children: listItems as Content[] as TxtListItemNode[], |
There was a problem hiding this comment.
Double type assertion (as Content[] as TxtListItemNode[]) is a code smell that suggests type safety issues. Consider refining the types to avoid the need for this double assertion.
No description provided.