Repository navigation
fix(migrate): auto-fix TS errors from Preact→React - #53
Merged
Merged
Conversation
- 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]>
|
🎉 This PR is included in version 0.36.5 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
altprop from non-img elements (<a>,<iframe>)typeprop from non-form elements (<span>,<div>)setTimeout/setIntervalwithwindow.for correct Node/CF Workers typingautoconfig.tsTS 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.altfrom non-img elements (<a>,<iframe>, etc.).typefrom non-form elements (<span>,<div>, etc.).setTimeout/setInterval/clearTimeout/clearIntervalwithwindow.for correct typing in Node/CF Workers.src/apps/autoconfig.ts.Written for commit 06df627. Summary will update on new commits.