Skip to content

πŸ› BUG: Incorrect parsing for exported typesΒ #1051

@MrTipson

Description

@MrTipson

What version of @astrojs/compiler are you using?

2.10.3

What package manager are you using?

pnpm

What operating system are you using?

Windows

Describe the Bug

When exporting certain kinds of types, the compiler can output code that ends up breaking up the type, leading to 'unexpected ' errors:

export type MyType = { foo: any
} & { bar: any }

ends up producing the following code, which (understandably) raises an Unexpected "&" error.

export type MyType = { foo: any
}
const $$Index = $$createComponent(($$result, $$props, $$slots) => {
const Astro = $$result.createAstro($$Astro, $$props, $$slots);
Astro.self = $$Index;
 & { bar: any }

I have confirmed this behavior for intersection, union and function types, but additional ones may exist.

While the issue can be worked around once you're aware of it, its:

  • not very easy to spot (since the typescript is correct in editor),
  • the resulting exceptions' stack traces are not useful and
  • the line number points at the wrong location in the file (or outside of it altogether).

Additionally, I believe this issue is closely related to #997.

Link to Minimal Reproducible Example

https://idx.google.com/type-export-bug-2501330

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions