Skip to content
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

Iterator method incorrectly fails with error when using emitIsolatedDts #9859

Open
ericrafalovsky opened this issue Jan 9, 2025 · 0 comments
Assignees
Labels
Milestone

Comments

@ericrafalovsky
Copy link

Describe the bug

swc decleration emit incorrectly fails with TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. when using an iterator method. See here for the expected behavior in the TypeScript compiler.

Input code

export class NumberRange implements Iterable<number> {
    private start: number;
    private end: number;

    constructor(start: number, end: number) {
        this.start = start;
        this.end = end;
    }

    [Symbol.iterator](): Iterator<number> {
        let current = this.start;
        const end = this.end;

        return {
            next(): IteratorResult<number> {
                if (current <= end) {
                    return { value: current++, done: false };
                } else {
                    return { value: undefined, done: true };
                }
            },
        };
    }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "experimental": {
        "emitIsolatedDts": true
    }
  },
  "sourceMaps": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.6&code=H4sIAAAAAAAAA42Rv07EMAzGd57CY6ur7gHag52F4W5EDGnrQqQ0rRzndAjl3cmfC22hA98QKf5s%2F%2BwEb%2FNEDJ0SxsCLHVuks9DvCHKcFY6o2cAzI4lW4UlH%2Fwm%2BHsBrJnkVjGBYENeQzGZjoe4XIzrdpA2T7XiiYlNYrZPLOyKIP6Q5xlR4TKxm6%2Fk67%2FgzxV0CvV4%2Bx3ZSRxmG97S3oqzTJv7ya5Mghf4VLJHf2HdboAssjg6JlsH3rYII2ZJedQzSeOM1%2BIzGKt7BZ8kBijzGKW5V7mSteXAVymKdhz8cKugn7QODUAbBNX%2BqHWBw%2FtfW6h4HqbHPbf3v7XfdRFz1c3X5X9w33uLZ%2Fm0CAAA%3D&config=H4sIAAAAAAAAA1WMOQ6AMAwEe14RueYF1DQUPCIKLoI4LNtIQYi%2FY64Iut0Z7W6Fc9BLgMptFq2QZ0HO3Yisk%2FpkBHQllMCRFMrXqpxKecGL7LcATIQcR7Tp8Dk7zRi1kXnwil2t8hsXzwHIvHDA1lP2%2BwE5e0RDqwAAAA%3D%3D

SWC Info output

No response

Expected behavior

Correctly typed code with [Symbol.iterator]() should be compatible with emitIsolatedDts

Actual behavior

No response

Version

1.10.6

Additional context

No response

@ericrafalovsky ericrafalovsky changed the title Iterator method Iterator method incorrectly fails with error when using emitIsolatedDts Jan 9, 2025
@kdy1 kdy1 added this to the Planned milestone Jan 10, 2025
@CPunisher CPunisher self-assigned this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants