Skip to content

fix(migrate): auto-fix TS errors from Preact→React - #53

Merged
JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/fix-ts-errors-migration
Mar 27, 2026
Merged

JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/fix-ts-errors-migration

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Remove invalid alt prop from non-img elements (<a>, <iframe>)
  • Remove invalid type prop from non-form elements (<span>, <div>)
  • Prefix setTimeout/setInterval with window. for correct Node/CF Workers typing
  • Fix autoconfig.ts TS error (explicit return type annotation)

Summary by cubic

Auto-fixes common TS/JSX issues from the Preact→React migration to unblock builds. Cleans invalid DOM props, normalizes timer typings, and fixes a missing return type in autoconfig.ts.

  • Bug Fixes
    • Remove alt from non-img elements (<a>, <iframe>, etc.).
    • Remove type from non-form elements (<span>, <div>, etc.).
    • Prefix setTimeout/setInterval/clearTimeout/clearInterval with window. for correct typing in Node/CF Workers.
    • Add explicit return type and safe empty-object cast in src/apps/autoconfig.ts.

Written for commit 06df627. Summary will update on new commits.

- Remove invalid `alt` prop from non-img elements (<a>, <iframe>)
- Remove invalid `type` prop from non-form elements (<span>, <div>)
- Prefix setTimeout/setInterval with window. for correct Node/CF typing
- Fix autoconfig.ts TS error (explicit return type annotation)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@JonasJesus42
JonasJesus42 merged commit 2cb5e0d into main Mar 27, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.36.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/migrate/transforms/jsx.ts">

<violation number="1" location="scripts/migrate/transforms/jsx.ts:201">
P2: The `: number` guard is too broad, so any file with a numeric type annotation will have *all* setTimeout/clearTimeout calls rewritten to `window.*`. This can break Node/SSR code where `window` is undefined. Narrow the check to only cases where the timer assignment is explicitly typed as `number`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

// setTimeout/setInterval return type: use window.setTimeout for correct typing
// In Node/CF Workers, setTimeout returns Timeout object, not number
// window.setTimeout always returns number
if (/\bsetTimeout\b/.test(result) && /:\s*number/.test(result)) {

@cubic-dev-ai cubic-dev-ai Bot Mar 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The : number guard is too broad, so any file with a numeric type annotation will have all setTimeout/clearTimeout calls rewritten to window.*. This can break Node/SSR code where window is undefined. Narrow the check to only cases where the timer assignment is explicitly typed as number.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/migrate/transforms/jsx.ts, line 201:

<comment>The `: number` guard is too broad, so any file with a numeric type annotation will have *all* setTimeout/clearTimeout calls rewritten to `window.*`. This can break Node/SSR code where `window` is undefined. Narrow the check to only cases where the timer assignment is explicitly typed as `number`.</comment>

<file context>
@@ -171,6 +171,55 @@ export function transformJsx(content: string): TransformResult {
+  // setTimeout/setInterval return type: use window.setTimeout for correct typing
+  // In Node/CF Workers, setTimeout returns Timeout object, not number
+  // window.setTimeout always returns number
+  if (/\bsetTimeout\b/.test(result) && /:\s*number/.test(result)) {
+    // Only replace bare setTimeout when it's assigned to a typed variable
+    result = result.replace(
</file context>
Suggested change
if (/\bsetTimeout\b/.test(result) && /:\s*number/.test(result)) {
if (/\bsetTimeout\b/.test(result) && /\b\w+\s*:\s*number\s*=\s*setTimeout\(/.test(result)) {
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant