-
Notifications
You must be signed in to change notification settings - Fork 59
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
Astro transform fails on several forms of multiline exports #554
Comments
Additional case reported on StackOverflow, which provides a CodeSandbox reproduction. Works---
import { SomeType } from 'package';
export type Props = SomeType & {
margin?: number | string
};
--- Doesn’t work---
import { SomeType } from 'package';
export type Props = {
margin?: number | string
} & SomeType;
--- Throws an error:
|
I see this issue marked as |
Just a note to anyone visiting this issue that exporting I'll bump the prio back to a p3 because people hit it often and formatting can trigger this automatically |
Prettier formats code with this syntax, and it works fine in Next.js (haven't tried in other projects), so why is this failing, here? Are unions like type Foo =
| string
| number; still valid TS (the documentation page no longer show this format). |
Yes, this is valid TS. It's a bug in our compiler, only affects exported things though |
I was able to work around this by defining the type separately from the function: type StaticPathResult = () => Promise<
{ params: { year: number }; props: Props }[]
>;
export const getStaticPaths: StaticPathResult = async () => {
// ...
} |
In my case it was prettier auto formatting forcing me into this issue. My current workaround is to transform this: type Test =
| 'this'
| 'test': to this: // prettier-ignore
type Test = 'this' | 'test' |
Just hit this issue for the first time. I can confirm that altering the line breaks somewhat combined with a |
I've hit this issue. Removing export resolves this issue export type TBlock =
| TBlock_Text
| TBlock_CardsList
| TBlock_CtaSection
| TBlock_Iframe
| TBlock_Hero; My work arround type TBlock_Union =
| TBlock_Text
| TBlock_CardsList
| TBlock_CtaSection
| TBlock_Iframe
| TBlock_Hero;
export TBlock = TBlock_Union |
What version of
astro
are you using?1.1.5
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
WSL2
Describe the Bug
(don't know if this should go in the compiler repo)
(Seems similar to the recently submitted #536, but found independently and (I think) more accurate on reproduction / diagnosing the cause.)
Astro fails at parsing certain forms of multiline exports (not sure exactly why), some of which are not uncommon patterns.
For context, I encountered this bug when trying to define a Props interface for a component, that extended a subset of some other defined type:
where I would consistently get an error message of
This error occurs not just for interfaces or generic types, but also for basic and union types if not on the same line as the
export
keyword (with slightly different expected/found in the error message):It's not restricted to types, either:
Notably, these issues only occur relating to some part of the expression going to a new line, and only when the expression in question is being exported: if the
export
keyword is removed, the transform no longer fails. This can be seen in the minimal reproduction example.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-hmtihg-ej7ccx?file=src/pages/index.astro
Participation
The text was updated successfully, but these errors were encountered: