Skip to content

Strictify TypeScript across viewer code – eliminate any usages and export missing prop types#719

Open
rushabhcodes wants to merge 1 commit intotscircuit:mainfrom
rushabhcodes:remove-any
Open

Strictify TypeScript across viewer code – eliminate any usages and export missing prop types#719
rushabhcodes wants to merge 1 commit intotscircuit:mainfrom
rushabhcodes:remove-any

Conversation

@rushabhcodes
Copy link
Contributor

This pull request improves type safety and code clarity in the CAD viewer codebase by introducing and exporting explicit prop types for the main viewer components and updating function signatures to use more specific types. The changes also update the context API to reflect these improvements.

Type safety and prop type improvements:

  • Introduced and exported CadViewerProps as a union of JscadProps and CadViewerManifoldProps, and updated the CadViewer and CadViewerInner components to use this type instead of any (src/CadViewer.tsx). [1] [2]
  • Exported the Props interface from src/CadViewerJscad.tsx for use as JscadProps elsewhere in the codebase.
  • Exported the CadViewerManifoldProps type from src/CadViewerManifold.tsx for use in the main viewer component.

Function signature and context API updates:

  • Updated the saveCameraToSession and loadCameraFromSession functions in src/contexts/CameraControllerContext.tsx to require a ThreeOrbitControls type for the controls parameter instead of any, and updated the context value accordingly. [1] [2] [3]

These changes improve code maintainability and reduce the risk of runtime errors by making prop and function types more explicit throughout the codebase.

Copilot AI review requested due to automatic review settings March 4, 2026 17:24
@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment Mar 4, 2026 5:25pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to “strictify” TypeScript types across the CAD viewer by exporting the previously-internal prop types for the JSCAD and Manifold viewer components, introducing a shared CadViewerProps type for the main CadViewer, and tightening the camera session helpers/context API to use ThreeOrbitControls instead of any.

Changes:

  • Export Props from CadViewerJscad and CadViewerManifoldProps from CadViewerManifold.
  • Introduce CadViewerProps in CadViewer and replace any usage in viewer component signatures.
  • Replace any with ThreeOrbitControls for camera session persistence APIs and their context typing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/contexts/CameraControllerContext.tsx Tightens camera session function/context types to ThreeOrbitControls rather than any.
src/CadViewerManifold.tsx Exports CadViewerManifoldProps for reuse by the main viewer component.
src/CadViewerJscad.tsx Exports Props for reuse as JscadProps elsewhere.
src/CadViewer.tsx Introduces CadViewerProps and replaces any, but currently relies on type assertions when passing props to each engine.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +34
import type { Props as JscadProps } from "./CadViewerJscad"
import type { CadViewerManifoldProps } from "./CadViewerManifold"

export type CadViewerProps = JscadProps | CadViewerManifoldProps

const CadViewerInner = (props: CadViewerProps) => {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CadViewerProps uses Props from CadViewerJscad directly, but CadViewerJscad is declared as React.PropsWithChildren<Props>. As a result, CadViewer/CadViewerInner props currently don’t properly model the children prop for the JSCAD path (e.g. <CadViewer soup={...}>{...}</CadViewer> won’t type-check). Consider defining the JSCAD side as React.PropsWithChildren<JscadBaseProps> (or exporting a JscadProps type that already includes children) before building CadViewerProps.

Copilot uses AI. Check for mistakes.
Comment on lines 249 to 260
<CadViewerJscad
{...props}
{...(props as JscadProps)}
autoRotateDisabled={props.autoRotateDisabled || !autoRotate}
cameraType={cameraType}
onUserInteraction={handleUserInteraction}
onCameraControllerReady={handleCameraControllerReady}
/>
) : (
<CadViewerManifold
{...props}
{...(props as CadViewerManifoldProps)}
autoRotateDisabled={props.autoRotateDisabled || !autoRotate}
cameraType={cameraType}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new CadViewerProps union is immediately bypassed via casts (props as JscadProps / props as CadViewerManifoldProps) when spreading into each engine component. This defeats the goal of eliminating any because the compiler can no longer ensure each branch receives the required props (notably CadViewerManifoldProps requires circuitJson or children). Prefer a discriminated union (e.g. an explicit engine prop) or a shared normalized prop shape so the branch props can be passed without type assertions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants