Skip to content

tsgo reports downstream TS2339 in ignored for-of over non-iterable union that tsc 6.0.2 does not #3487

@songkeys

Description

@songkeys

TypeScript Version

  • tsc 6.0.2
  • tsgo 7.0.0-dev.20260421.2

Search Terms

for...of, @ts-ignore, TS2488, TS2339, error recovery, parity

Code

type A = {
  a: string
}

type B = {
  b: string
}

declare const data: A[] | B

// @ts-ignore
for (const item of data) {
  item.b
}

Commands

tsc --ignoreConfig --noEmit --strict --target es2022 case4.ts
tsc --ignoreConfig --noEmit --strict --target es2022 --stableTypeOrdering case4.ts
tsgo --ignoreConfig --noEmit --strict --target es2022 case4.ts

Expected Behavior

tsgo should match tsc 6.0.2 here.

With the @ts-ignore on the for...of line, tsc 6.0.2 reports no errors, including with --stableTypeOrdering.

Actual Behavior

tsgo reports:

case4.ts(13,8): error TS2339: Property 'b' does not exist on type 'A'.

Additional Notes

If I remove the @ts-ignore, tsc 6.0.2 reports only the for...of error (TS2488), while tsgo reports both the TS2488 and the downstream TS2339 in the loop body.

So this appears to be a parity difference in error recovery or loop variable typing after an invalid for...of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions