compiler icon indicating copy to clipboard operation
compiler copied to clipboard

Props Type parsing fails when using union/ intersection types without brackets

Open space-otter opened this issue 2 years ago • 1 comments

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

When using union or intersection type definitions on Props the transformation fails. For example:

---
export type Props = {
  specs: {
    name: string;
  };
} & {
  additional: string;
}

const { specs, additional } = Astro.props as Props;

Results in Unexpected "&"

Quick Fix:

---
export type Props = ({
  specs: {
    name: string;
  };
} & {
  additional: string;
})

const { specs, additional } = Astro.props as Props;

Semantically both examples should be the same.

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal?file=src/components/Test.astro

Participation

  • [ ] I am willing to submit a pull request for this issue.

space-otter avatar Mar 12 '23 14:03 space-otter

The repro link doesn't look right, but here's a repro based on the description. This seems to be a compiler issue.

bluwy avatar Mar 13 '23 14:03 bluwy

Duplicate of https://github.com/withastro/compiler/issues/554

Princesseuh avatar Jul 23 '24 12:07 Princesseuh