Hacker News new | ask | show | jobs
by npn 1099 days ago
you clearly don't know what you are talking about.

reactive declarations do not change the type of the objects. it just that they can rerun when the dependencies change.

sure for the convenience of the users you do not need to type `let vars...` for every new variable declared in the reactive statement, but no one forbid you to write it before hand, or let the language server/plugin do it for you.

but Svelte indeed do not work perfectly with typescript, because it allows you to write code inside html template, which currently only support javascript expression.

3 comments

Data-point of one, but I have definitely run into issues where Typescript can't understand what's going on in a reactive expression, and had to aggressively refactor my code to make everything happy. Most of the time it works great, but when it doesn't it can be really annoying. I wouldn't go so far as to say it doesn't play well, but the seams are definitely visible.
Could be the plugin was broken somehow. Happen all the time for me. Even now the syntax highlighting and code formatting feature would break if I write the code the wrong way.

from my understanding the plugin does some clever tricks like insert some dummy code or create some dummy files to be consumed by the typescript language server. so it is not guaranteed to be correct 100% of the time.

I mean, that sounds like a data point of two now to me - you're also saying that Typescript and Svelte don't play that nice together if the plug-in breaks "all the time" and you need to be careful how you write code just to get correct syntax highlighting and code formatting, no?
Syntax highlighting and code formatting sometime break because Svelte file is single file component format, which mean it has script, markup and style in a single file. It's rather complex to parse it right, especially when you use regexes to do the job like in VS Code.

It's just the problem with the VS Code Svelte extension, not the framework itself nor because of Typescript. Also for my case, it happens because I prefer to not use semicolons in my code, not because it is typescript.

Maybe, but Vue also has SFCs, and I've never once had issues with syntax highlighting or code formatting there.
the distinct difference between Vue and Svelte is html in Vue need to be wrapped in `<template>` tag. There is no such restriction in Svelte SFCs.
This simply isn't true. For instance, if you narrow a variable from `1 | 2 | 3` to `1 | 2`, then trigger a reactive declaration, the reactive declaration can't understand that you've narrowed the variable, and you lose that information. Same thing happens if you go the opposite direction and broaden a variable. TS assumes that program flow roughly goes from top to bottom; if you break that invariant you lose a lot of handy features.

> you clearly don't know what you are talking about.

huh?

I think the claim is that it breaks TS parsing, not that it changes the type.
Then it's wrong too. Because it is perfectly valid js code. It is just that they repurpose the label syntax (used for breaking out of inner loops) for the reactive statement.