S
SolidJS2mo ago
gsoutz

Cant set signal from getting another signal typescript error

function update<T>(target: Accessor<T | undefined>) {

let [current, set_current] = createSignal<T | undefined>(undefined)

set_current(target())
}
function update<T>(target: Accessor<T | undefined>) {

let [current, set_current] = createSignal<T | undefined>(undefined)

set_current(target())
}
No overload matches this call.
The last overload gave the following error.
Argument of type 'T | undefined' is not assignable to parameter of type 'Exclude<T, Function> | ((prev: T | undefined) => T | undefined) | undefined'.
Type 'T' is not assignable to type 'Exclude<T, Function> | ((prev: T | undefined) => T | undefined) | undefined'.(2769)
signal.d.ts(109, 3): The last overload is declared here.
(parameter) target: () => T | undefined
No overload matches this call.
The last overload gave the following error.
Argument of type 'T | undefined' is not assignable to parameter of type 'Exclude<T, Function> | ((prev: T | undefined) => T | undefined) | undefined'.
Type 'T' is not assignable to type 'Exclude<T, Function> | ((prev: T | undefined) => T | undefined) | undefined'.(2769)
signal.d.ts(109, 3): The last overload is declared here.
(parameter) target: () => T | undefined
https://playground.solidjs.com/anonymous/3218adfe-fd03-4d61-9763-02637001ca22
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
4 Replies
gsoutz
gsoutz2mo ago
And what happens if i do this which compiles btw: set_current(target)
binajmen
binajmen2mo ago
set_current(() => target()) should work although i'm not sure what you are trying to achieve
gsoutz
gsoutz2mo ago
the inner function to immedately called right when I set this. why can't i just do as i tried above.
binajmen
binajmen2mo ago
still not sure to understand the end goal of update. it might help if you provided a more complete example as update is used nowhere set_current(target) should work as well
Want results from more Discord servers?
Add your server