-
Notifications
You must be signed in to change notification settings - Fork 179
types(global): add Window interface declarations for simulator globals #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
types(global): add Window interface declarations for simulator globals #675
Conversation
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughA new TypeScript global type declarations file is added that extends the Window interface with optional properties for DOM utilities, authentication state, project identifiers, UI settings, and display dimensions. No runtime code is introduced; only type definitions are added. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/types/global.d.ts (3)
7-8: Consider installing jQuery type definitions.While
anyworks for eliminating@ts-ignorecomments, consider installing@types/jqueryif jQuery is used extensively across the codebase. This would provide better type safety and autocompletion.Apply this approach if jQuery is a major dependency:
npm install --save-dev @types/jqueryThen update the declarations:
- $?: any - jQuery?: any + $?: JQueryStatic + jQuery?: JQueryStatic
10-10: Remove redundant| undefinedfrom optional properties.The
?operator already makes properties optional (meaning they can beundefined). Explicitly adding| undefinedto the type union is redundant.Apply this diff to remove the redundancy:
- logixProjectId?: number | string | undefined + logixProjectId?: number | string - projectId?: number | string | undefined - id?: number | string | undefined + projectId?: number | string + id?: number | string - width?: number | undefined - height?: number | undefined + width?: number + height?: numberAlso applies to: 14-15, 18-19
11-11: Consider more specific typing forrestrictedElements.The property uses
any[]which provides minimal type safety. If the structure of restricted elements is known, consider defining a more specific type or interface.For example:
interface RestrictedElement { // Define properties based on actual usage id: string type: string // ... other properties } // Then in the Window interface: restrictedElements?: RestrictedElement[]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/types/global.d.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ThatDeparted2061
Repo: CircuitVerse/cv-frontend-vue PR: 442
File: src/simulator/src/wire.ts:0-0
Timestamp: 2025-01-27T17:29:33.929Z
Learning: In the CircuitVerse frontend Vue project, globalScope should be declared on the window object using TypeScript declaration files (.d.ts) rather than importing it as a module.
Learnt from: ThatDeparted2061
Repo: CircuitVerse/cv-frontend-vue PR: 442
File: src/simulator/src/wire.ts:0-0
Timestamp: 2025-01-27T17:29:33.929Z
Learning: In the CircuitVerse frontend Vue project, globalScope is a global variable that should be typed by extending the Window interface in a TypeScript declaration file (global.d.ts), as it's initialized on the window object.
📚 Learning: 2025-01-27T17:29:33.929Z
Learnt from: ThatDeparted2061
Repo: CircuitVerse/cv-frontend-vue PR: 442
File: src/simulator/src/wire.ts:0-0
Timestamp: 2025-01-27T17:29:33.929Z
Learning: In the CircuitVerse frontend Vue project, globalScope should be declared on the window object using TypeScript declaration files (.d.ts) rather than importing it as a module.
Applied to files:
src/types/global.d.ts
📚 Learning: 2025-01-27T17:29:33.929Z
Learnt from: ThatDeparted2061
Repo: CircuitVerse/cv-frontend-vue PR: 442
File: src/simulator/src/wire.ts:0-0
Timestamp: 2025-01-27T17:29:33.929Z
Learning: In the CircuitVerse frontend Vue project, globalScope is a global variable that should be typed by extending the Window interface in a TypeScript declaration file (global.d.ts), as it's initialized on the window object.
Applied to files:
src/types/global.d.ts
🔇 Additional comments (1)
src/types/global.d.ts (1)
1-5: LGTM! Correct structure for global augmentation.The file structure is correct with
export {}making this a module, which allows thedeclare globalblock to extend the Window interface. The comment clearly explains the purpose of type-only augmentation.Based on learnings.

Fixes #661
Describe the changes you have made in this PR -
Added a new type declaration file (
src/types/global.d.ts) defining commonwindowproperties used across the simulator (e.g.,globalScope,lightMode,projectId,embed, etc.).This improves TypeScript type safety and removes the need for repetitive
@ts-ignorecomments.Screenshots of the changes (If any) -
Note: Please check Allow edits from maintainers. ✅
Summary by CodeRabbit