tsconfig update for v0.13.1

Hey Guys, in your migration guide you state, that one should add two new lines to the tsconfig.json file. When I do so, my typings for Server-Operations don't work anymore.
.js
import { GetMyOperation } from 'wasp/server/operations'

type functionType = GetMyOperation<ArgsType, ReturnType>
type params = Parameters<functionType>
type returnn = ReturnType<functionType>
.js
import { GetMyOperation } from 'wasp/server/operations'

type functionType = GetMyOperation<ArgsType, ReturnType>
type params = Parameters<functionType>
type returnn = ReturnType<functionType>
This was working just fine before and still is with v0.13.1 but not anymore after adding this tsconfig. Then the type import cannot be resolved and thus params is unknown and returnn is any. Any idea on what i am doing wrong here? If i add only "target": "esnext" to the config it already fails. And i can not add moduleResolution on its own. @sodic You suggested this change in an other thread, so maybe you are the right person to ask? (sorry to bother you)
No description
23 Replies
kapa.ai
kapa.ai7mo ago
Hi @Gwaggli. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided don't contain specific information about the issue you're encountering with the tsconfig.json update for v0.13.1 and the Server-Operations typings. However, it's worth noting that there have been discussions about managing tsconfig.json files in Wasp, and the idea of Wasp checking if they are there, generating them if they're not, and fixing them if something is wrong has been suggested (source (https://github.com/wasp-lang/wasp/issues/939)). There have also been changes in Wasp 0.12.0 that deprecated some issues related to tsconfig.json files (source (https://github.com/wasp-lang/wasp/issues/1057), source (https://github.com/wasp-lang/wasp/issues/1415)). I recommend checking the official Wasp documentation or reaching out to the Wasp community for more specific guidance on your issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Gwaggli, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Filip
Filip7mo ago
Hmm, good question @Gwaggli. We might have messed something up. Can you give me full info for reproducing this: - Screenshot of the error - The Wasp file and the operation file where the error occurs (if not private). Or, ideally, your entire project in a zip or a github repo 😄 - Also, are you getting the error in your editor or during the build?
@sodic You suggested this change in an other thread, so maybe you are the right person to ask? (sorry to bother you)
And no problem at all! I'm here to help 😄
Gwaggli
Gwaggli7mo ago
Thanks for getting back to me! I just reproduced this with a clean wasp project:
main.wasp
app test {
wasp: {
version: "^0.13.1"
},
title: "test"
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}


action myAction {
fn: import { myAction } from "@src/server/actions.js",
entities: []
}
main.wasp
app test {
wasp: {
version: "^0.13.1"
},
title: "test"
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}


action myAction {
fn: import { myAction } from "@src/server/actions.js",
entities: []
}
And then a simple action:
.js
import { MyAction } from "wasp/server/operations";

type Args = {};
type Result = {};

type functionType = MyAction<Args, Result>;
type params = Parameters<functionType>;
type returnn = ReturnType<functionType>;

export const myAction = () => {};
.js
import { MyAction } from "wasp/server/operations";

type Args = {};
type Result = {};

type functionType = MyAction<Args, Result>;
type params = Parameters<functionType>;
type returnn = ReturnType<functionType>;

export const myAction = () => {};
With the standard configuration the import resolve fails and thus the typings can not be inferred. Error: Cannot find module 'wasp/server/operations' or its corresponding type declarations.ts(2307)
No description
Filip
Filip7mo ago
Excellent! Thank you very much, I'll get right on it Unrelated tip: You should capitalize your type names. Nothing to do with the error, but it's a standard in TS (FunctionType instead of functionType, etc.) I can't reproduce this. I've started your project and everything works normally Just a second
Gwaggli
Gwaggli7mo ago
Ah yeah, normally i do 😄 just forgot in this example 😄 Am i right that i need to use TS version 5.1.0 or is there a way to upgrade this? (could that be the source of the issue?)
Filip
Filip7mo ago
No, TS 5.1.0 should be fine (and there's no easy way for you to update it yet) Did you try to restart the TS language server? Here's a snippet from a doc page that we lost (but plan to bring back)
Your editor may sometimes report type and import errors even while wasp start is running. This happens when the TypeScript Language Server gets out of sync with the current code. If you're using VS Code, you can manually restart the language server by opening the command palette and selecting "TypeScript: Restart TS Server."
Try it in the example repro project while wasp start is running. Also, check the terminal - are there any errors there?
Gwaggli
Gwaggli7mo ago
Hmm weird, I did that before already but maybe exactly at the wrong time 😄
Filip
Filip7mo ago
If it works in your small example repro app, try it in the real thing It's still possible you're getting a different error there
Gwaggli
Gwaggli7mo ago
But follow up: If you add this line: const test: MyAction<Args, Result> = async (args, context) => {}; Do you get the type inference on the parameters? I lose them once I switch the config to esnext. But get them, when i remove the target option.
No description
No description
Gwaggli
Gwaggli7mo ago
I now see, that the import resolving was never the issue (this was TS Server dependent) and also works in my real app. But the type inference in the methods parameters does not work in either.
Filip
Filip7mo ago
Yes, I can definitely reproduce this. Congratulations, you've found a bug (and a big one too)!
MEE6
MEE67mo ago
Wohooo @sodic, you just became a Waspeteer level 30!
Filip
Filip7mo ago
I'll dig into it and keep you posted Thanks for hte help
Gwaggli
Gwaggli7mo ago
Haha thank you! Let me know if I can be of any Help 🙂
Filip
Filip7mo ago
Ok, I believe I've found the issue. I'll do my best to get the fix out today.
Gwaggli
Gwaggli7mo ago
Damn you're a machine! 😄
Filip
Filip7mo ago
In the meantime, here's a quick fix you can use: In .wasp/out/sdk/wasp/package.json, add the following line to the exports object:
"exports": {
// ...
"./server/_types": "./dist/server/_types/index.js",
// ...
}
"exports": {
// ...
"./server/_types": "./dist/server/_types/index.js",
// ...
}
Haha, thanks for the kind words, but this is mostly becuase I happen to know the creator of this bug very well
Gwaggli
Gwaggli7mo ago
Your fix did the job for me 👍 Hahaha yeah fair, but still. Nice job and greatly appreciate the help and insane speed 😄
Filip
Filip7mo ago
Great to hear! Keep in mind that Wasp might regenerate that file at one point, which will remove the fix you added. If you want a command that you can quickly run from the terminal to do this edit for you, here it is.
# Run from the root of your project
jq '.exports += {"./server/_types": "./dist/server/_types/index.js"}' .wasp/out/sdk/wasp/package.json > temp.json && mv temp.json .wasp/out/sdk/wasp/package.json
# Run from the root of your project
jq '.exports += {"./server/_types": "./dist/server/_types/index.js"}' .wasp/out/sdk/wasp/package.json > temp.json && mv temp.json .wasp/out/sdk/wasp/package.json
If you don't have jq installed, I highly recommend you get it. It's an awesome tool: https://github.com/jqlang/jq I'll let you know as soon as the release with the fix is out
Gwaggli
Gwaggli7mo ago
Great, thanks! I am not developing atm so I dont need this workaround but thank you anyways! didn't know about jq. Thanks for the help. Much appreciated 🙂
Filip
Filip7mo ago
Hey @Gwaggli, the new version of Wasp that fixes this error is finally out (sorry it took until today 😅) As always, you can install it with curl:
curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s
curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s
There are no braking changes so all your old project will work automatically 🙂
Gwaggli
Gwaggli7mo ago
Great news, thank you so much!
Want results from more Discord servers?
Add your server