-
-
Notifications
You must be signed in to change notification settings - Fork 209
Strict types: Await block with Observables using the $ syntax, Property 'then' does not exist on '' #358
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
Comments
It's a svelte2tsx issue, the code assumes it's a promise. Honestly I did not even know this is possible. |
Well it seems it's just half-supported(?), and I opened another issue on the main repo sveltejs/svelte#5206 because the await and error blocks never render with regular observables. There is timhall's https://github.com/timhall/svelte-observable lib which does solve this problem but the (The mentioned issue contains a larger snippet with the mentioned svelte-observable case, if that helps) |
I look at the source of svelte's handle_promise, It seems like if the value awaiting is not a
Along with the issue mention here By the way, if there is an error it won't be handled. because it doesn't wrap it with a try-catch. but
, when the value awaiting is a PromiseLike |
And I believe this should be reflected by the types aswell, as I said the solution using that |
Yeah. it needs to be supported. Typescript also allow you to await on anything. But it also got me thinking what the point of this await anymore? You can't catch any errors even if svelte wrap a try catch in the generated code. Because it's similar to the following: let a = 1
try {
const value = await a;
} catch (error) {
//Do something
} |
True, catching will never work, but the "show loading while no value, show then if there's a value" will work. |
Based on this issue and this comment
rxjs
observables withawait
blocks are supported. sveltejs/svelte#2571 (comment)And indeed this code snippet does the job and works (Except errors and the unresolved state but that a different issue), but it also produces a TypeScript error, and one more if
strict
settings (noImplicitAny
to be precise) are enabled.tsconfig.json
app.svelte
any
in a catch should always be allowed as you can't even specify types of errors in regularcatch
blocks either. TS knows this, of course, and the interesting part is when usingPromises
in the template,e
in the:catch
block still has anany
type but that does not produce an error, only with Observables.The text was updated successfully, but these errors were encountered: