Skip to content

TSTypeAssertion is not implemented by the Svelte compiler #15565

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

Closed
mazen-isstech opened this issue Mar 21, 2025 · 2 comments · Fixed by #15642
Closed

TSTypeAssertion is not implemented by the Svelte compiler #15565

mazen-isstech opened this issue Mar 21, 2025 · 2 comments · Fixed by #15642

Comments

@mazen-isstech
Copy link

mazen-isstech commented Mar 21, 2025

Describe the bug

The Svelte compiler is not handling what the parser calls, TSTypeAssertion AST nodes.

About Typescript type assertions: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions

Whenever the compiler encounters such a cast-expression, it throws the error:

Not implemented TSTypeAssertion

This is not a critical bug, but is an annoyance as sometimes a type checker is unable to deduce the true types of some expressions, which can cause several false positives. Casting is what help "patch" these issues.

Reproduction

https://svelte.dev/playground/hello-world?version=5.23.2#H4sIAAAAAAAAA22OywrCMBBFfyXOJi2IxW1MC-78B-OitmMNxGlIxhel_25iXbq7HO6ZuRNQe0NQcEDnRvEcg-tFgb1l7EtYw8U6jKCOE_Db514Gif-svfeb-EDHmZ3biP94NxIjcToDOnbBehaupaGWHGVjyLBDFllUInKwNIha6CU1opDfTbLcGdLVomeJ9HXbLKOn7M4rXSViKD1kfDEoDnecT_MH1_OZN-IAAAA=

Logs

None provided, see reproduction.

System Info

System and binaries are the same as https://svelte.dev/playground/ (console says it's running Svelte compiler version 5.23.2).

Browsers:
  Brave Browser: 134.1.76.74

Severity

annoyance

@Ocean-OS
Copy link
Contributor

This isn't a direct bug in Svelte, rather it seems like a combination of bugs in both @sveltejs/acorn-typescript and esrap. I tried to make a fix, but there's some weird differences between acorn-typescript and @sveltejs/acorn-typescript that I can't resolve.
For now I'd recommend using TypeScript's as type assertion syntax, like so:

let name: string = 'world' as string;

@mazen-isstech
Copy link
Author

@Ocean-OS Okay, I see. Anyway, thank you for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants