I want to create a signal input with a transform attribute but the compiler throws an error:
foo = input<string, number>(0, {transform: numberAttribute });
Error:
Argument of type 'number' is not assignable to parameter of type 'string'.
What is the issue ?
The short answer is : try to not type your signals and let the inference do its job.
foo = input(0, {transform: numberAttribute });
Playground demo for signal input type inference
The signal type definition is wrong. InputSignal has 2 generics : ReadT and WriteT.
ReadT is the type of your signal when you read it, WriteT is the type of the input.
So your signal input should be the other way around:
foo = input<number, string>(0, {transform: numberAttribute });
Not also that, using unknown is also possible:
foo = input<unknown, number>(300, { transform: numberAttribute });
Having to define both is actually due to a Typescript limitation, it doesn't support partial type inference so it's not possible to do this at the moment:
// will works when TS supports partial type inference
delay = input<number>(300, { transform: numberAttribute });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With