Closed weijarz closed 3 years ago
For TypeScript, all the functions passed to setState
, except the last one, need explicit types for their parameters.
There's no error if todo
parameter type is spelled out:
setState('todos', (todo: {task: string; completed: boolean}) => todo.completed, 'task', t => t + '!')
The code in Solid examples is javascript. TypeScript type inference has its limits. Here there are multiple parameters with inter-dependent types which it can't figure out without some help.
As far as I know @fictitious is correct. These are very difficult types and have been the effort of many of the community to get right. There are still gaps though. So I'd welcome anyone who has the knowledge to look at this but realistically this is probably beyond my or any of the team member's current TypeScript knowledge to address.
Type improvements were made and query answered. Closing.
To Reproduce
Code snippet from: https://www.solidjs.com/docs/latest/api#updating-stores
Expected behavior
The example code copied from Solid document will cause typescript error on filter function.
Reproduction
https://playground.solidjs.com/?version=1.1.1#NobwRAdghgtgpmAXGGUCWEwBowBcCeADgsrgM4Ae2YZA9gK4BOAxiWGjIbY7gAQi9mjOFFxwAyrm5xeAX14AzRrRi8AOjVoAbNABMAtACsyAejJThGgNxqIt5rQjnewc6LhZeZOLknuAurwAvILC7pLSABQgtry8Urq0ZIgusXH88VBkANYpAOQAYhhoZAAWvADu3Nl5ng6cWj5wuikKUFreclhpcQK4Wbm8eQDitLwA5sqsjPhepbSEhBjjtYIqhI1iLYrtnbLdEOkZ-Tn5ALJQ2TK6GBBwjKv1G03bbR0ysmn+trIAlDZOHx+MSRPIJJKrcHBAB88VoiQAdE9Ns1PGCBpCYfFeABqIYAQjyv1sYFk-iAA