Open kenkunz opened 1 year ago
Hi, @kenkunz thanks for reporting this! Do you mind explaining what you mean by
TypeScript <> cast operator console.log(\<string>x);
it's the first time I've ever heard of this. The newest TS version doesn't compile here either: https://www.typescriptlang.org/play?#code/MYewdgziA2CmB00QHMAUAeCAXATgSzGQD4APASgG4AoIA
Are you sure this is valid syntax?
Hi @lforst – thanks for looking into this.
Are you sure this is valid syntax?
Here's the documentation on Type Assertions from the official Typescript docs: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions
You can also use the angle-bracket syntax (except if the code is in a
.tsx
file), which is equivalent:const myCanvas = <HTMLCanvasElement>document.getElementById("main_canvas");
Ah. TIL I guess we need to turn off JSX for the parser then!
cc @Lms24 I don't see any immediate option to do this in magicast, maybe we need to pass in a custom parser?
@Lms24 side note – I just saw your Svienna talk on the state of Sentry for Svelte (via Svelte Society YouTube channel)… nice overview… gut getan!
Hi @kenkunz thanks for letting us know about this!
I don't see any immediate option to do this in magicast, maybe we need to pass in a custom parser?
I think this gives us a good reason to switch to recast, providing one of the recast parsers actually supports this syntax. Gonna add this to my to do list for this week.
TIL:
This is the AST of <string>x
when parsing with the typescript parser
+1
I have the same problem right now. Luckily, I can still manually wrap the load functions.
Hey, sorry that this slipped through 😬 Unfortunately, I'm/we're blocked by a lot of other work at the moment so I can't give you an ETA for fixing this.
For now, @fromaline's suggestion to manually wrap load functions is probably the best workaround if you have to rely on the angle bracket style type assertions. From what I can tell, there's no difference to using as <Type>
type assertions which should work fine with our auto instrumentation plugin. But obviously I don't want to force you to change your code just for Sentry. Whatever works for you best!
@Lms24, thanks for the explanation! No worries, it's not a deal-breaker.
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io) as well as self-hosted (same issue occurs in both environments).
Which SDK are you using?
@sentry/sveltekit
SDK Version
7.74.1
Framework Version
1.26.0
Link to Sentry event
https://zenthropic.sentry.io/issues/4559398012/?project=4504934292258816
SDK Setup
Steps to Reproduce
I created a new minimum SvelteKit repro with Sentry to demonstrate this bug.
Create new SvelteKit project
src/routes/+page.ts
file with a TypeScript<>
cast operatorvite.config.ts
to disable auto-instrumentation:Expected Result
No error should occur at step 5.
Auto-instrumentation should not (incorrectly) interpret TypeScript cast operator
<>
as JSX.Current work-around: using
as
cast operator instead of<>
.Actual Result
The following error occurs at step 5.