issue: https://linear.app/comm/issue/ENG-4457/refactor-sessionid-field
Adding sessionID to keyserverStore. Not reducing it yet.
Details
Tested that sessionID field is present in the keyseverStore. Checked that it is set to the same value as sessionID initilly.
Ran yarn flow-all.
Diff Detail
- Repository
- rCOMM Comm
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
lib/utils/sanitization.js | ||
---|---|---|
298 ↗ | (On Diff #29138) | This issue is not present in the newest flow, so I'm assuming it can be ignored. I tried fixing it, but didn't manage to Cannot spread object literal because null or undefined [1] is incompatible with undefined [2] in property `sessionID`.Flow(incompatible-type) |
307 ↗ | (On Diff #29138) | This issue is present in the newest flow. Cannot assign object literal to `state` because null or undefined [1] is incompatible with undefined [2] in property `sessionID` of the indexer property of property `keyserverStore.keyserverInfos`.Flow(incompatible-type) flow doesn't know which KeyserverInfo type keyserverInfos has. I couldn't fix this, but this code is very straightforward |
Not a fan of using *, from what I understand that's basically any. I think we could use generics instead (we could also replace the * that existed before if we are changing the code anyway). There's also the option of using empty in places where we aren't using the generic fields, which would be "safer" because we wouldn't be able to use them, but this doesn't feel very clear.
lib/types/keyserver-types.js | ||
---|---|---|
12 ↗ | (On Diff #29138) | What is the reason for using ... and $Exact<>? |
38 ↗ | (On Diff #29138) | Nit: can we name it keyserverInfoType or something more descriptive? |
lib/utils/sanitization.js | ||
298 ↗ | (On Diff #29138) | Can you make a task for it and add it to ENG-4283 so we don't forget about it? |
Agree with @michal... wondering, what if we use a default type param here? Then we could just use BaseAppState<>.
To declare a default type param, add an = DefaultType after the : BaseType. Often you use the same type for both, eg. BaseAppState<NavInfo: BaseNavInfo = BaseNavInfo>, which causes BaseAppState<> to expand into BaseAppState<BaseNavInfo>
lib/types/keyserver-types.js | ||
---|---|---|
12 ↗ | (On Diff #29138) | Using ... makes the type behave more like an interface - it's possible to have a function that takes infos: BaseKeyserverInfos and pass any of WebKeyserverInfo or NativeKeyserverInfo to it (but only be able to access properties from BaseKeyserverInfo). I could have instead done: export type BaseKeyserverInfo = { +cookie?: ?string, }; export type WebKeyserverInfo = { ...BaseKeyserverInfo, +sessionID: ?string, }; export type NativeKeyserverInfo = { ...BaseKeyserverInfo, +sessionID?: void, }; it's just a bit less flexible. But since we have WebKeyserverInfo, NativeKeyserverInfo and KeyserverInfo in lib, I guess I can always use KeyserverInfo wherever I'd want to use BaseKeyserverInfo as an "interface". So if you think I should change it, then it shouldn't be a problem. |
wondering, what if we use a default type param here?
No, this causes errors
Cannot call useSelector with threadInfoSelector bound to selector because undefined [1] is incompatible with null or undefined [2] in property sessionID of type argument KeyserverInfoType [3] of property keyserverStore of the first parameter. [incompatible-call]
I think we could use generics instead
I can't use generis for consts, mixed also doesn't seem to work
Managed to remove all // Flow-issues, but there is one type error hidden under that clone any typed
I reabsed over D8686 and removed the * from my changes. Me @michal and @tomek spent a lot of time trying to make the solution with two KeyserverInfos work, but we couldn't get it to work without flow errors. We figured it's not worth spending so much time on.
I created https://linear.app/comm/issue/ENG-4568/improve-sessionid-type to fix this at some point, but for now I will type sessionID as sessionID?: ?string, and use the same KeyserverInfo for web and native. This significantly simplifies the code. As of now, there should be no other fields that have different type on web than on native, so this issue shouldn't reoccur for now
Okay, fair enough – I agree it's not worth that much effort. Especially if all three of you had trouble