-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve feat/transitions type #410
fix: improve feat/transitions type #410
Conversation
This lets non-shallow updates be notified of server rendering loading status, using an external `React.useTransition` hook.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
556b9a5
to
2fc399b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very interesting approach!
suggestion: We could use better descriptive names for generic types than B and S (S stands for Shallow I guess, but is B for Boolean?)
issue: The end-to-end test bench fails to compile (run with pnpm test
):
e2e:build: Failed to compile.
e2e:build:
e2e:build: ./src/pages/pages/useQueryState/index.tsx:40:43
e2e:build: Type error: Type 'false' is not assignable to type 'undefined'.
e2e:build:
e2e:build: 38 | <button
e2e:build: 39 | id="string_set_a"
e2e:build: > 40 | onClick={() => setString('a', { shallow: false })}
e2e:build: | ^
e2e:build: 41 | >
e2e:build: 42 | Set A
e2e:build: 43 | </button>
Any way to get around it in TS? Sorry my brain is not functioning... function Test() {
const [state, setName] = useQueryState('name')
const [isLoading, startTransition] = React.useTransition()
return (
<>
{/* failed Type '{}' is not assignable to type 'boolean | undefined'. */}
<button
id="string_set_a"
onClick={() =>
setName('a', {
shallow: {}
})
}
>
Set A
</button>
{/* failed Type 'TransitionStartFunction' is not assignable to type 'undefined'.ts(2322)
*/}
<button
id="string_set_a"
onClick={() =>
setName('a', { shallow: true, startTransition: startTransition })
}
>
Set A
</button>
<button
id="string_set_a"
onClick={() =>
setName('a', { shallow: false, startTransition: startTransition })
}
>
Set A
</button>
<button
id="string_set_a"
onClick={() => setName('a', { shallow: false })}
>
Set A
</button>
<button
id="string_set_a"
onClick={() => setName('a', { startTransition: startTransition })}
>
Set A
</button>
</>
)
} |
d69624f
to
12a6cda
Compare
c62384d
to
12a6cda
Compare
I don't think it is going to be feasible. Update: Typescript is not omnipotent; you must admit the unknowability of shallow option to Typescript before processing it through type exclusion logic. I think we can’t pass all the tests without introducing unknown because typescript doesn't check if Update: Update: |
7928355
to
1990b7e
Compare
a3a8537
to
0e2355b
Compare
0a23d71
to
0e2355b
Compare
@franky47 This is the best I can do. Please approve this PR if you are happy with it. |
8eeea93
to
c233c0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Great job! 👏
There are many corner cases where we could end up, like chaining withOptions
, or overriding hook-level options with call-level ones, but I realised that the type for the Options object still make sense to be boolean | undefined
and React.TransitionStartFunction | undefined
, as the setting of shallow: false
when passing a startTransition
is not done when defining options, but when they get merged when applied to the URL queue.
* feat: Add support for transitions This lets non-shallow updates be notified of server rendering loading status, using an external `React.useTransition` hook. * fix: improve typing * fix: better typing * fix: remove unnecessary code * chore: remove unnecessary changes * fix: some edge cases when shallow is not a boolean type * fix: remove as any * fix: e2e build * chore: better name for generic * fix: parser type * fix: better naming * fix: better naming * chore: better naming * test: Add type tests for shallow/startTransition interaction * fix: simplify type * test: add a extra test case * chore: extract type exclusion logic * chore: simplify types * chore: remove unnecessary generics * chore: add test case for startTransition * test: Add type tests * chore: Simplify type & prettify --------- Co-authored-by: Francois Best <[email protected]>
* feat: Add support for transitions This lets non-shallow updates be notified of server rendering loading status, using an external `React.useTransition` hook. * fix: improve typing * fix: better typing * fix: remove unnecessary code * chore: remove unnecessary changes * fix: some edge cases when shallow is not a boolean type * fix: remove as any * fix: e2e build * chore: better name for generic * fix: parser type * fix: better naming * fix: better naming * chore: better naming * test: Add type tests for shallow/startTransition interaction * fix: simplify type * test: add a extra test case * chore: extract type exclusion logic * chore: simplify types * chore: remove unnecessary generics * chore: add test case for startTransition * test: Add type tests * chore: Simplify type & prettify --------- Co-authored-by: Francois Best <[email protected]>
* feat: Add support for transitions This lets non-shallow updates be notified of server rendering loading status, using an external `React.useTransition` hook. * test: Add e2e test for transitions * fix: improve the Option type for transitions (#410) * feat: Add support for transitions This lets non-shallow updates be notified of server rendering loading status, using an external `React.useTransition` hook. * fix: improve typing * fix: better typing * fix: remove unnecessary code * chore: remove unnecessary changes * fix: some edge cases when shallow is not a boolean type * fix: remove as any * fix: e2e build * chore: better name for generic * fix: parser type * fix: better naming * fix: better naming * chore: better naming * test: Add type tests for shallow/startTransition interaction * fix: simplify type * test: add a extra test case * chore: extract type exclusion logic * chore: simplify types * chore: remove unnecessary generics * chore: add test case for startTransition * test: Add type tests * chore: Simplify type & prettify --------- Co-authored-by: Francois Best <[email protected]> * doc: Add transitions docs --------- Co-authored-by: Jon Sun <[email protected]>
@franky47
Re: #406 (comment)