Open ANDREA-1720 opened 2 weeks ago
Actually the code was supposed to look like, but the result is the same, it is only easier to see that the function test() runs only on the server :
import { createSignal } from "solid-js";
function test(toLog: string) {
"use server";
console.log(toLog);
return "pressed"
}
export default function Example() {
const [text, setText] = createSignal("TEST")
return (
<button type="button" class="text-white" onClick={() => test("test").then((text: string) => {setText(text)})}>
{ text() }
</button>
);
}
It's kinda expected that you define all use server
functions as async function
or const ... = async () =>
, getting typescript to help here would probably require a plugin
I understand, it can be kinda unintuitive though. I think that one solution may be to either force a function with "use server" in it to be asynchronous, or maybe make the non asynchronous one to do not return a Promise, but directly the returned value (I understand both of these are, possibly, breaking changes... but I think these options are far more intuitive than the current implementation)
Duplicates
Latest version
Current behavior 😯
When calling a function with inside "use server", it always returns a promise, but typescript set the type to the one of the return, causing the IDE to mark a type error
EXAMPLE CODE:
ERROR:
RESULT: The code perfectly work
Expected behavior 🤔
When calling a function with inside "use server", it always returns a promise, and TypeScript know that
EXAMPLE CODE:
NO ERROR:
RESULT: The code perfectly work
Steps to reproduce 🕹
Steps:
bun create solid
selecting to use typescript, with solidStartbun dev
EXAMPLE CODE:
Context 🔦
No response
Your environment 🌎