fix: signal setter callback form incorrect prev parameter type#682
Merged
ryansolid merged 1 commit intosolidjs:mainfrom Oct 9, 2021
Merged
fix: signal setter callback form incorrect prev parameter type#682ryansolid merged 1 commit intosolidjs:mainfrom
ryansolid merged 1 commit intosolidjs:mainfrom
Conversation
Pull Request Test Coverage Report for Build 1320346031
💛 - Coveralls |
fbc3483 to
b8caf6e
Compare
rturnq
reviewed
Oct 9, 2021
| ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: U) => U)) => U | ||
| : <U extends T>(v: (U extends Function ? never : U) | ((prev: U) => U)) => U; | ||
| ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: T) => U)) => U | ||
| : <U extends T>(v: (U extends Function ? never : U) | ((prev: T) => U)) => U; |
Member
There was a problem hiding this comment.
I think the whole setter function should also return T rather than U for the same reason as prev. As it is the return value will be narrowed to the new value only. Consider the following:
const [signal, setSignal] = createSignal(false) // boolean
let value = setSignal(true) // typeof value has been narrowed to true
value = false // Error: Type 'false' is not assignable to type 'true'
Contributor
Author
There was a problem hiding this comment.
This test wants the setter to return U though. I also disagree that it should return T for the same reason as prev should be type T; the type of prev can't be known by the callback whereas the setter will always return U when passed U or a callback that returns U.
test("Set signal returns argument", () => {
const [_, setValue] = createSignal<number>();
const res1: undefined = setValue(undefined);
expect(res1).toBe(undefined);
const res2: number = setValue(12);
expect(res2).toBe(12);
const res3 = setValue(Math.random() >= 0 ? 12 : undefined);
expect(res3).toBe(12);
const res4 = setValue();
expect(res4).toBe(undefined);
});
Member
There was a problem hiding this comment.
Sounds good.. want to move on the release tonight so going to merge and make the other change.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously the
prevparameter would erroneously be the same as the return type of the callback, instead of any type the signal could hold; see TS playground.