-
-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some inaccurate typings and Selector bug (#327)
* Fix incorrect argument type of createEffect When an initial value is passed to createComputed, createRenderEffect or createEffect, and the return type of the passed function doesn't include undefined, the argument will never be undefined either. Additionally, when no initial value is given, there is no reason to restrict the return type to a defined value. The code can handle undefined values just fine. Some examples that fail to typecheck, but work in practice have been added as test cases. This commit adds overloads to the mentioned functions to remove undefined from the argument type when an initial value is given, and allow undefined in the return type otherwise. * Fix types of functions which can return undefined The setter returned by `createSignal()` accepts an optional argument, but returns a non-optional type. This commit adds a test case where this results in incorrectly typing an undefined value as defined. Similarly, `createContext()` creates a context with a default value of undefined. However, when used in `useContext()`, it will return a non-undefined type. This is possible because `lookup()` returns `any`. Typescript incorrectly assumed that `any` equals `T` and forgets that it could also be undefined. This commit works around that by encoding the possible undefined in the `T` stored in `Context<>`. * Fix selector not working when passing falsy value The primary use for selectors is using an array index as key. This means that the value `0` is likely to be used quite often. However, due to the use of a falsy check instead of an undefined check, passing 0 will not cause an update when the key is unset. This is demonstrated by a test. This commit replaces the falsy check with an undefined check.
- Loading branch information
Showing
2 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters