-
Notifications
You must be signed in to change notification settings - Fork 2k
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
TSC: Fix unsupported TS syntax in getTransformedStreamItems
selector
#73991
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
Made this a draft as I'm still working on it. |
fb78ad4
to
758f84f
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.
This is ready for a review 👀
Doing a self-review, too.
@@ -26,7 +26,7 @@ interface Options< A extends unknown[] > { | |||
getCacheKey?: GenerateCacheKey< A >; | |||
} | |||
|
|||
interface CachedSelector< S, A extends unknown[], R = unknown > { | |||
export interface CachedSelector< S, A extends unknown[], R = unknown > { |
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.
Necessary as without it we were also getting this error:
Exported variable 'getTransformedStreamItems' has or is using name 'CachedSelector' from external module "/calypso/packages/tree-select/src/index" but cannot be named.
getReaderStream( state, streamKey ).items, | ||
getReaderStream( state, recsStreamKey ).items, | ||
getReaderFollows( state ), | ||
], | ||
( [ items, recs, follows ] ) => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
( [ items, recs, follows ]: Array< any > ) => { |
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.
Here's the magic. For some reason, TS needs this type explicitly, although it's properly specified in treeSelect
's types.
@@ -17,12 +17,13 @@ import 'calypso/state/reader/init'; | |||
* function( state, { streamKey: string, recsStreamKey: string }): Array | |||
*/ | |||
export const getTransformedStreamItems = treeSelect( | |||
( state, { streamKey, recsStreamKey } ) => [ | |||
( state, { streamKey, recsStreamKey }: { streamKey: string; recsStreamKey: string } ) => [ |
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.
Necessary only to complete the type definition. Went the simple inline way, no need for abstractions IMHO.
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.
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.
This seems to work and I can run tsc
again!
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.
Tested locally, and now I can runyarn run typecheck
(yarn run tsc --project client
).
Thanks for jumping in and helping us to fix it. :)
Proposed Changes
While working on #73890 I stumbled upon an error that I see when I run
yarn tsc --noEmit --project client/tsconfig.json
:The fix is straightforward: we're renaming the offending file from
.js
to.ts
and specifying a type for the deps argument of thetreeSelect
'sselector
argument. Without the type, TS was crashing.This has also been reported in #66894.
Fixes #66894.
Testing Instructions
trunk
locally.yarn tsc --noEmit --project client/tsconfig.json
Pre-merge Checklist