Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal input with transform issue with transform

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 ?

like image 467
Matthieu Riegler Avatar asked Aug 27 '26 15:08

Matthieu Riegler


1 Answers

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 long answer

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 }); 
like image 189
Matthieu Riegler Avatar answered Aug 29 '26 05:08

Matthieu Riegler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!