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
chore: bump node, rethinkdb-ts, typescript, uWS #7780
Conversation
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
e353e68
to
1ffeccd
Compare
@@ -36,7 +36,7 @@ const defaultExecutor: Executor<{ | |||
}) | |||
clearTimeout(timeout) | |||
const resJSON = (await result.json()) as EndpointExecutionResult | {message?: string} | |||
if ('data' in resJSON || 'errors' in resJSON) return resJSON |
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.
I think I found a bug in typescript!
...or I'm just an idiot.
Either way, I made an issue for it here: microsoft/TypeScript#52812
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.
oh wow
Let's change the code to the a little bit easier to read equivalent of if ('data' in resJSON || 'errors' in resJSON) return resJSON
if ('data' in resJSON) return resJSON
if ('errors' in resJSON) return resJSON
TS complains because data
is a mandatory property, and technically the second case indicates the data is not defined.
Let's follow the code execution of if ('data' in resJSON || 'errors' in resJSON) return resJSON
- if
data
is in theresJSON
it'll go straight toreturn resJSON
as there's no need to check second condition in theor
logical statement if first part is true, the returned type will be{ data, errors? }
- the second part of the logical
or
will be executed only ifdata
is not in theresJSON
, meaning it'll return a type{ errors }
, and TS will complain asdata
is mandatory
Here's what happens in the reversed version ie. if ('errors' in resJSON || 'data' in resJSON) return resJSON
- if
errors
is in theresJSON
and type narrowing assumes if theoptional
property of type is there, then the mandatory has to be there - the second part will be executed only if there are no
errors
, and if true the returned type will be{ data }
which is a valid return type
I still get Property 'data' is missing in type '{ message?: string | undefined; } & Record<"errors", unknown>' but required in type 'EndpointExecutionResult'.ts(2322)
error on master here but VS code sometimes is misleading so I created a TS playground
and seems like the way type narrowing works has changed, actually!
if (!ws.connectionContext) return | ||
ws.done = true | ||
const handleClose = (ws: WebSocket<SocketUserData>) => { | ||
const userData = ws.getUserData() |
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.
with the new version of uWS, we can't just assign objects to the WebSocket object. we have to get a UserData
object off of it & assign our stuff there.
import ConnectionContext from '../socketHelpers/ConnectionContext' | ||
import keepAlive from '../socketHelpers/keepAlive' | ||
import {sendEncodedMessage} from '../socketHelpers/sendEncodedMessage' | ||
import handleConnect from './handleConnect' | ||
|
||
const APP_VERSION = process.env.npm_package_version | ||
export type SocketUserData = { |
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.
tbh, i kinda like that they make us do this. it's more explicit.
@@ -6,7 +6,7 @@ import getQueryToken from '../utils/getQueryToken' | |||
import sendToSentry from '../utils/sendToSentry' | |||
import uwsGetIP from '../utils/uwsGetIP' | |||
|
|||
const handleUpgrade: WebSocketBehavior['upgrade'] = async (res, req, context) => { | |||
const handleUpgrade: WebSocketBehavior<void>['upgrade'] = async (res, req, context) => { |
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.
during upgrade we don't have any UserData
yet, so this is the exception where we use void
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.
I tested everything I can think of locally and seems everything seems to be good!
CHANGELOG.md
Outdated
- | ||
|
||
### Added | ||
|
||
- chore: Migrate MeetingTemplate to PG (Phase 1 of 3) (#7679) | ||
- chore(checkout-flow): add checkout feature flag (#7709) | ||
- | ||
|
||
### Changed | ||
|
||
- chore: update team invite email (#7710) | ||
- chore(ai-summary): update meeting summary url (#7705) | ||
- |
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.
+1 no need for empty -
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.
i have no idea why my markdown plugin automatically added those... will fix
@@ -171,7 +171,7 @@ export default class LocalCache<T extends keyof CacheType> { | |||
Object.keys(this.cacheMap).forEach((key) => { | |||
if (!key.startsWith(`${table}:`)) return | |||
const doc = this.cacheMap[key] | |||
Object.assign(doc, updater) | |||
Object.assign(doc as any, updater) |
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.
+1 I see TS is complaining about doc
being possibly undefined
so seems like the correct solution here would be to add {}
in this case so Object.assign
won't try to write to undefined
, am I correct?
const doc = this.cacheMap[key] || {}
Object.assign(doc, updater)
not related to PR but this file comment on the top says it's only used for User
table but seems like it's only being used for meeting templates, is that something we should fix? also, once we migrate to postgres, is there any need for this functionality?
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.
heh, yeah this file is very old & only used by 1 thing, it will absolutely go away when we move to pg so i didn't take too much time making it perfect. just want it to stop complaining until i can delete it 🙂
@@ -36,7 +36,7 @@ const defaultExecutor: Executor<{ | |||
}) | |||
clearTimeout(timeout) | |||
const resJSON = (await result.json()) as EndpointExecutionResult | {message?: string} | |||
if ('data' in resJSON || 'errors' in resJSON) return resJSON |
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.
oh wow
Let's change the code to the a little bit easier to read equivalent of if ('data' in resJSON || 'errors' in resJSON) return resJSON
if ('data' in resJSON) return resJSON
if ('errors' in resJSON) return resJSON
TS complains because data
is a mandatory property, and technically the second case indicates the data is not defined.
Let's follow the code execution of if ('data' in resJSON || 'errors' in resJSON) return resJSON
- if
data
is in theresJSON
it'll go straight toreturn resJSON
as there's no need to check second condition in theor
logical statement if first part is true, the returned type will be{ data, errors? }
- the second part of the logical
or
will be executed only ifdata
is not in theresJSON
, meaning it'll return a type{ errors }
, and TS will complain asdata
is mandatory
Here's what happens in the reversed version ie. if ('errors' in resJSON || 'data' in resJSON) return resJSON
- if
errors
is in theresJSON
and type narrowing assumes if theoptional
property of type is there, then the mandatory has to be there - the second part will be executed only if there are no
errors
, and if true the returned type will be{ data }
which is a valid return type
I still get Property 'data' is missing in type '{ message?: string | undefined; } & Record<"errors", unknown>' but required in type 'EndpointExecutionResult'.ts(2322)
error on master here but VS code sometimes is misleading so I created a TS playground
and seems like the way type narrowing works has changed, actually!
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Description
lastIndexOf
lastIndexOf
closed
that conflicts. EDIT: i can just resolve rethinkdb-ts to a higher version & it works great.Demo
Everything just works 🤞
Test
biggest changes are with uWS, so test refreshing the page, subscriptions, etc.