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

Nested TypeScript generics are causing the compiler to error out #8209

Closed
tajo opened this issue Nov 2, 2023 · 1 comment · Fixed by #8607
Closed

Nested TypeScript generics are causing the compiler to error out #8209

tajo opened this issue Nov 2, 2023 · 1 comment · Fixed by #8607
Assignees
Labels
Milestone

Comments

@tajo
Copy link

tajo commented Nov 2, 2023

Describe the bug

It seems that some more complex nested TypeScript generics that should be valid are causing SWC to error out.

Input code

const Context = createContext<<Key extends keyof Config>(key: Key) => Config[Key]>(                                  
  (key) => properties[key]?.default
);

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "transform": {
      "optimizer": {
        "globals": {
          "vars": {
            "__NODE__": false
          }
        },
        "simplify": {
          "preserveImportsWithSideEffects": false
        },
      },
    },
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.94-nightly-20231016.1&code=H4sIAAAAAAAAA0vOzysuUXDOzytJrShRsFVILkpNLEmF8m1svFMrFYCM1LyUYoXs1Mr8NJDStMx0Ow0gz0oBKK2pYGsHFYwGcmPtNBQIAi4FBZB%2BsNaCovyC1KKSzNTiaKBQrL1eSmpaYmlOCZemNQB3IiWKnAAAAA%3D%3D&config=H4sIAAAAAAAAA2WRMXPCMAyF9%2F6KnGYGLkOHzjB0KB06dMy5QQ7m7NhnCa6By3%2BvHOKA6SZ%2FT3ovka4vVQVHauGtukopj6AiYVzeQmjoWf0KAR4CUhtNYFhllSlJHE84kfEmAKvYIachpHpd15B5VD1pH91jgg9snLkUsYI763%2BUpQIKPssXPjGhTbP73GybRhQtQ%2Figjks9ru7uZFywRg%2FP9iGiLOCM7y74yPRt%2BPBl9rjVGlumf%2FaL5VzkBVjvCXP3zJzpy0BovUt5VDamVtV3Fou09BuTOzi%2FP03ifLN0l9uqX%2BHelMMWYzD0kSeng41%2F9m8fyP8BAAA%3D

SWC Info output

No response

Expected behavior

const Context = createContext((key) => properties[key]?.default);

Actual behavior

  x Expected a semicolon
   ,-[1:1]
 1 | const Context = createContext<<Key extends keyof Config>(key: Key) => Config[Key]>(                                  
   :                                    ^^^^^^^
 2 |   (key) => properties[key]?.default
 3 | );
   `----

  x Expression expected
   ,-[1:1]
 1 | const Context = createContext<<Key extends keyof Config>(key: Key) => Config[Key]>(                                  
 2 |   (key) => properties[key]?.default
 3 | );
   : ^
   `----


Caused by:
    0: failed to parse code
    1: Syntax Error

Version

1.3.94-nightly-20231016.1

Additional context

No response

@tajo tajo added the C-bug label Nov 2, 2023
@kdy1 kdy1 added this to the Planned milestone Nov 2, 2023
@kdy1 kdy1 self-assigned this Nov 2, 2023
yannkaiser added a commit to yannkaiser/swc that referenced this issue Feb 6, 2024
@kdy1 kdy1 closed this as completed in #8607 Feb 6, 2024
@kdy1 kdy1 closed this as completed in 9e6dad9 Feb 6, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.1 Feb 13, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 14, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 participants