You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Using sapper with the preload function inside module script gives a bad DX.
exportasyncfunctionpreload(page,session){// <------- not typed, need to add typings yourselfconstres=awaitthis.fetch(`blog/${slug}.json`);// <--- error, what it `this`?}
Describe the solution you'd like
Support typing for the preload function and for this, but in such a way that it will not also provide these for non-sapper-projects.
Notes / open questions
this probably needs to be transformed to some ambient global which has fetch defined on it.
preload is tricky because it's not a usage of something we can provide in the ambient context, but a definition . Not sure how to implement this.
How to only provide these typings/transformations in a Sapper project? How can we determine this? Look into the package.json?
The text was updated successfully, but these errors were encountered:
After some more thought and hearing that the context is possibly user-modifiable in the future, I'm deciding against baking this into the language-tools.
getting arguments ambiently typed is not possible
typing this is possible to do by the user, and since it may be modified, our typings may be wrong anyway in the future
How to type this this (hah) then?
You can type the this context of a function explicitly in TypeScript (see docs):
// Better move that into some file and do `import type { PreloadContext } from ...` to not type it every timeinterfacePreloadContext{fetch: ...,
...
}// won't work with export const preload = (...exportasyncfunctionpreload(this: PreloadContext, ...page/session,ifyouneedit){
...
this.fetch(...)// <-- works without type errors}
Is your feature request related to a problem? Please describe.
Using sapper with the
preload
function inside module script gives a bad DX.Describe the solution you'd like
Support typing for the preload function and for this, but in such a way that it will not also provide these for non-sapper-projects.
Notes / open questions
this
probably needs to be transformed to some ambient global which hasfetch
defined on it.preload
is tricky because it's not a usage of something we can provide in the ambient context, but a definition . Not sure how to implement this.package.json
?The text was updated successfully, but these errors were encountered: