-
-
Notifications
You must be signed in to change notification settings - Fork 833
Fix getRelationsForEvent
under TypeScript strict
mode
#9558
Fix getRelationsForEvent
under TypeScript strict
mode
#9558
Conversation
eventId: string, | ||
relationType: RelationType | string, | ||
eventType: EventType | string, | ||
) => Relations | null | undefined; |
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.
Not every event has relations so of course we should be able to return undefined
.
Unless of course there can be an empty Relations
object? Since Relations(relationType, eventType, client)
requires relationType
I don't think this is the case.
getRelationsForEvent
tsc strictnessgetRelationsForEvent
under TypeScript strict
mode
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.
Looks good to me.
Did a quick test on the Netlify Deployment 👍
"the top answer - assuming no best answer", | ||
); | ||
return ""; | ||
} |
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.
On the other hand: Having tests before fixing strict type things would give us confidence that it is still working (as expected).
@@ -484,7 +484,7 @@ export default class MPollBody extends React.Component<IBodyProps, IState> { | |||
const totalVotes = this.totalVotes(votes); | |||
const winCount = Math.max(...votes.values()); | |||
const userId = this.context.getUserId(); | |||
const myVote = userVotes?.get(userId)?.answers[0]; | |||
const myVote = userVotes?.get(userId!)?.answers[0]; |
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.
We can use !
here because a Map
lookup with null
or undefined
will still give an undefined
myVote
which is acceptable in the logic below.
…m:matrix-org/matrix-react-sdk into madlittlemods/strict-getRelationsForEvent
Thanks for the review @weeman1337 and merge @turt2live 🐾 |
* Fix getRelationsForEvent tsc strictness * Use shared type for GetRelationsForEvent * Fix lint * Add alternative type * getRelationsForEvent is not required * Relations are optional * Reactions are optional * We expect relations in these tests * Add more protection if the eventID is not defined * Allow null too * Better test typing * User ID is not necessary unless something is selected * It's okay to [].includes(null) * Null is as good as undefined here * Null or undefined is good here * We have some expectations for the tests * The room and user can be undefined too * Protec * Reactions are optional * Try match signatures * Null or undefined * More null or undefined * Protec * Fix typo (wrong variable) * Remove optional params See #9558 (comment) * Fix up last maaaaybe relevant lint Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
Fix
getRelationsForEvent
under TypeScriptstrict
modeSpawning from an unrelated spot that I got yelled at for in #8354. There is too much to fix to include in that PR if we want to get that right:
Checklist
Sign-off given on the changes (see CONTRIBUTING.md)This change is marked as an internal change (Task), so will not be included in the changelog.