Skip to content

Commit 8d018f9

Browse files
authored
Enable noImplicitAny (#2895)
* Stash noImplicitAny work * Enable noImplicitAny * Update olm * Fun * Fix msgid stuff * Fix tests * Attempt to fix Browserify
1 parent 6f81371 commit 8d018f9

File tree

83 files changed

+1613
-1426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1613
-1426
lines changed

.github/workflows/static_analysis.yml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,46 +64,11 @@ jobs:
6464

6565
- name: Generate Docs
6666
run: "yarn run gendoc"
67-
67+
6868
- name: Upload Artifact
6969
uses: actions/upload-artifact@v3
7070
with:
7171
name: docs
7272
path: _docs
7373
# We'll only use this in a workflow_run, then we're done with it
7474
retention-days: 1
75-
76-
tsc-strict:
77-
name: Typescript Strict Error Checker
78-
if: github.event_name == 'pull_request'
79-
runs-on: ubuntu-latest
80-
permissions:
81-
pull-requests: read
82-
checks: write
83-
steps:
84-
- uses: actions/checkout@v3
85-
86-
- name: Get diff lines
87-
id: diff
88-
uses: Equip-Collaboration/[email protected]
89-
with:
90-
include: '["\\.tsx?$"]'
91-
92-
- name: Detecting files changed
93-
id: files
94-
uses: futuratrepadeira/[email protected]
95-
with:
96-
repo-token: ${{ secrets.GITHUB_TOKEN }}
97-
pattern: '^.*\.tsx?$'
98-
99-
- uses: t3chguy/typescript-check-action@main
100-
with:
101-
repo-token: ${{ secrets.GITHUB_TOKEN }}
102-
use-check: false
103-
check-fail-mode: added
104-
output-behaviour: annotate
105-
ts-extra-args: '--noImplicitAny'
106-
files-changed: ${{ steps.files.outputs.files_updated }}
107-
files-added: ${{ steps.files.outputs.files_created }}
108-
files-deleted: ${{ steps.files.outputs.files_deleted }}
109-
line-numbers: ${{ steps.diff.outputs.lineNumbers }}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build:dev": "yarn clean && git rev-parse HEAD > git-revision.txt && yarn build:compile && yarn build:types",
1515
"build:types": "tsc -p tsconfig-build.json --emitDeclarationOnly",
1616
"build:compile": "babel -d lib --verbose --extensions \".ts,.js\" src",
17-
"build:compile-browser": "mkdirp dist && browserify -d src/browser-index.js -p [ tsify -p ./tsconfig-build.json ] -t [ babelify --sourceMaps=inline --presets [ @babel/preset-env @babel/preset-typescript ] ] | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js",
17+
"build:compile-browser": "mkdirp dist && browserify -d src/browser-index.ts -p [ tsify -p ./tsconfig-build.json ] -t [ babelify --sourceMaps=inline --presets [ @babel/preset-env @babel/preset-typescript ] ] | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js",
1818
"build:minify-browser": "terser dist/browser-matrix.js --compress --mangle --source-map --output dist/browser-matrix.min.js",
1919
"gendoc": "typedoc",
2020
"lint": "yarn lint:types && yarn lint:js",
@@ -33,9 +33,9 @@
3333
"matrix-org"
3434
],
3535
"main": "./src/index.ts",
36-
"browser": "./lib/browser-index.js",
36+
"browser": "./lib/browser-index.ts",
3737
"matrix_src_main": "./src/index.ts",
38-
"matrix_src_browser": "./src/browser-index.js",
38+
"matrix_src_browser": "./src/browser-index.ts",
3939
"matrix_lib_main": "./lib/index.js",
4040
"matrix_lib_typings": "./lib/index.d.ts",
4141
"author": "matrix.org",
@@ -80,7 +80,7 @@
8080
"@babel/preset-typescript": "^7.12.7",
8181
"@babel/register": "^7.12.10",
8282
"@casualbot/jest-sonar-reporter": "^2.2.5",
83-
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.13.tgz",
83+
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz",
8484
"@types/bs58": "^4.0.1",
8585
"@types/content-type": "^1.1.5",
8686
"@types/domexception": "^4.0.0",

spec/TestClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class TestClient {
183183
this.httpBackend.when('POST', '/keys/query').respond<IDownloadKeyResult>(
184184
200, (_path, content) => {
185185
Object.keys(response.device_keys).forEach((userId) => {
186-
expect(content.device_keys![userId]).toEqual([]);
186+
expect((content.device_keys! as Record<string, any>)[userId]).toEqual([]);
187187
});
188188
return response;
189189
});

spec/browserify/setupTests.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import "../../dist/browser-matrix"; // uses browser-matrix instead of the src
18-
import type { MatrixClient, ClientEvent } from "../../src";
19-
20-
declare global {
21-
// eslint-disable-next-line @typescript-eslint/no-namespace
22-
namespace NodeJS {
23-
interface Global {
24-
matrixcs: {
25-
MatrixClient: typeof MatrixClient;
26-
ClientEvent: typeof ClientEvent;
27-
};
28-
}
29-
}
30-
}
18+
import type { default as BrowserMatrix } from "../../src/browser-index";
3119

3220
// stub for browser-matrix browserify tests
3321
// @ts-ignore
@@ -43,4 +31,4 @@ afterAll(() => {
4331
global.matrixcs = {
4432
...global.matrixcs,
4533
timeoutSignal: () => new AbortController().signal,
46-
};
34+
} as typeof BrowserMatrix;

spec/browserify/sync-browserify.spec.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
import HttpBackend from "matrix-mock-request";
1818

19-
import "./setupTests";// uses browser-matrix instead of the src
19+
import "./setupTests"; // uses browser-matrix instead of the src
2020
import type { MatrixClient } from "../../src";
2121

2222
const USER_ID = "@user:test.server";
@@ -65,15 +65,16 @@ describe("Browserify Test", function() {
6565
const syncData = {
6666
next_batch: "batch1",
6767
rooms: {
68-
join: {},
69-
},
70-
};
71-
syncData.rooms.join[ROOM_ID] = {
72-
timeline: {
73-
events: [
74-
event,
75-
],
76-
limited: false,
68+
join: {
69+
[ROOM_ID]: {
70+
timeline: {
71+
events: [
72+
event,
73+
],
74+
limited: false,
75+
},
76+
},
77+
},
7778
},
7879
};
7980

spec/integ/devicelist-integ.spec.ts

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ROOM_ID = "!room:id";
3030
*
3131
* @return {object} sync response
3232
*/
33-
function getSyncResponse(roomMembers) {
33+
function getSyncResponse(roomMembers: string[]) {
3434
const stateEvents = [
3535
testUtils.mkEvent({
3636
type: 'm.room.encryption',
@@ -43,12 +43,10 @@ function getSyncResponse(roomMembers) {
4343

4444
Array.prototype.push.apply(
4545
stateEvents,
46-
roomMembers.map(
47-
(m) => testUtils.mkMembership({
48-
mship: 'join',
49-
sender: m,
50-
}),
51-
),
46+
roomMembers.map((m) => testUtils.mkMembership({
47+
mship: 'join',
48+
sender: m,
49+
})),
5250
);
5351

5452
const syncResponse = {
@@ -73,8 +71,8 @@ describe("DeviceList management:", function() {
7371
return;
7472
}
7573

76-
let sessionStoreBackend;
77-
let aliceTestClient;
74+
let aliceTestClient: TestClient;
75+
let sessionStoreBackend: Storage;
7876

7977
async function createTestClient() {
8078
const testClient = new TestClient(
@@ -97,7 +95,10 @@ describe("DeviceList management:", function() {
9795
});
9896

9997
it("Alice shouldn't do a second /query for non-e2e-capable devices", function() {
100-
aliceTestClient.expectKeyQuery({ device_keys: { '@alice:localhost': {} } });
98+
aliceTestClient.expectKeyQuery({
99+
device_keys: { '@alice:localhost': {} },
100+
failures: {},
101+
});
101102
return aliceTestClient.start().then(function() {
102103
const syncResponse = getSyncResponse(['@bob:xyz']);
103104
aliceTestClient.httpBackend.when('GET', '/sync').respond(200, syncResponse);
@@ -138,7 +139,10 @@ describe("DeviceList management:", function() {
138139

139140
it.skip("We should not get confused by out-of-order device query responses", () => {
140141
// https://github.com/vector-im/element-web/issues/3126
141-
aliceTestClient.expectKeyQuery({ device_keys: { '@alice:localhost': {} } });
142+
aliceTestClient.expectKeyQuery({
143+
device_keys: { '@alice:localhost': {} },
144+
failures: {},
145+
});
142146
return aliceTestClient.start().then(() => {
143147
aliceTestClient.httpBackend.when('GET', '/sync').respond(
144148
200, getSyncResponse(['@bob:xyz', '@chris:abc']));
@@ -164,11 +168,12 @@ describe("DeviceList management:", function() {
164168
aliceTestClient.httpBackend.flush('/keys/query', 1).then(
165169
() => aliceTestClient.httpBackend.flush('/send/', 1),
166170
),
167-
aliceTestClient.client.crypto.deviceList.saveIfDirty(),
171+
aliceTestClient.client.crypto!.deviceList.saveIfDirty(),
168172
]);
169173
}).then(() => {
170-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
171-
expect(data.syncToken).toEqual(1);
174+
// @ts-ignore accessing a protected field
175+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
176+
expect(data!.syncToken).toEqual(1);
172177
});
173178

174179
// invalidate bob's and chris's device lists in separate syncs
@@ -201,15 +206,16 @@ describe("DeviceList management:", function() {
201206
return aliceTestClient.httpBackend.flush('/keys/query', 1);
202207
}).then((flushed) => {
203208
expect(flushed).toEqual(0);
204-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
209+
return aliceTestClient.client.crypto!.deviceList.saveIfDirty();
205210
}).then(() => {
206-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
207-
const bobStat = data.trackingStatus['@bob:xyz'];
211+
// @ts-ignore accessing a protected field
212+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
213+
const bobStat = data!.trackingStatus['@bob:xyz'];
208214
if (bobStat != 1 && bobStat != 2) {
209215
throw new Error('Unexpected status for bob: wanted 1 or 2, got ' +
210216
bobStat);
211217
}
212-
const chrisStat = data.trackingStatus['@chris:abc'];
218+
const chrisStat = data!.trackingStatus['@chris:abc'];
213219
if (chrisStat != 1 && chrisStat != 2) {
214220
throw new Error(
215221
'Unexpected status for chris: wanted 1 or 2, got ' + chrisStat,
@@ -234,12 +240,13 @@ describe("DeviceList management:", function() {
234240
// wait for the client to stop processing the response
235241
return aliceTestClient.client.downloadKeys(['@bob:xyz']);
236242
}).then(() => {
237-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
243+
return aliceTestClient.client.crypto!.deviceList.saveIfDirty();
238244
}).then(() => {
239-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
240-
const bobStat = data.trackingStatus['@bob:xyz'];
245+
// @ts-ignore accessing a protected field
246+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
247+
const bobStat = data!.trackingStatus['@bob:xyz'];
241248
expect(bobStat).toEqual(3);
242-
const chrisStat = data.trackingStatus['@chris:abc'];
249+
const chrisStat = data!.trackingStatus['@chris:abc'];
243250
if (chrisStat != 1 && chrisStat != 2) {
244251
throw new Error(
245252
'Unexpected status for chris: wanted 1 or 2, got ' + bobStat,
@@ -255,15 +262,16 @@ describe("DeviceList management:", function() {
255262
// wait for the client to stop processing the response
256263
return aliceTestClient.client.downloadKeys(['@chris:abc']);
257264
}).then(() => {
258-
return aliceTestClient.client.crypto.deviceList.saveIfDirty();
265+
return aliceTestClient.client.crypto!.deviceList.saveIfDirty();
259266
}).then(() => {
260-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
261-
const bobStat = data.trackingStatus['@bob:xyz'];
262-
const chrisStat = data.trackingStatus['@bob:xyz'];
267+
// @ts-ignore accessing a protected field
268+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
269+
const bobStat = data!.trackingStatus['@bob:xyz'];
270+
const chrisStat = data!.trackingStatus['@bob:xyz'];
263271

264272
expect(bobStat).toEqual(3);
265273
expect(chrisStat).toEqual(3);
266-
expect(data.syncToken).toEqual(3);
274+
expect(data!.syncToken).toEqual(3);
267275
});
268276
});
269277
});
@@ -285,10 +293,11 @@ describe("DeviceList management:", function() {
285293
},
286294
);
287295
await aliceTestClient.httpBackend.flush('/keys/query', 1);
288-
await aliceTestClient.client.crypto.deviceList.saveIfDirty();
296+
await aliceTestClient.client.crypto!.deviceList.saveIfDirty();
289297

290-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
291-
const bobStat = data.trackingStatus['@bob:xyz'];
298+
// @ts-ignore accessing a protected field
299+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
300+
const bobStat = data!.trackingStatus['@bob:xyz'];
292301

293302
// Alice should be tracking bob's device list
294303
expect(bobStat).toBeGreaterThan(
@@ -322,10 +331,11 @@ describe("DeviceList management:", function() {
322331
);
323332

324333
await aliceTestClient.flushSync();
325-
await aliceTestClient.client.crypto.deviceList.saveIfDirty();
334+
await aliceTestClient.client.crypto!.deviceList.saveIfDirty();
326335

327-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
328-
const bobStat = data.trackingStatus['@bob:xyz'];
336+
// @ts-ignore accessing a protected field
337+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
338+
const bobStat = data!.trackingStatus['@bob:xyz'];
329339

330340
// Alice should have marked bob's device list as untracked
331341
expect(bobStat).toEqual(
@@ -359,15 +369,14 @@ describe("DeviceList management:", function() {
359369
);
360370

361371
await aliceTestClient.flushSync();
362-
await aliceTestClient.client.crypto.deviceList.saveIfDirty();
372+
await aliceTestClient.client.crypto!.deviceList.saveIfDirty();
363373

364-
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
365-
const bobStat = data.trackingStatus['@bob:xyz'];
374+
// @ts-ignore accessing a protected field
375+
aliceTestClient.client.cryptoStore!.getEndToEndDeviceData(null, (data) => {
376+
const bobStat = data!.trackingStatus['@bob:xyz'];
366377

367378
// Alice should have marked bob's device list as untracked
368-
expect(bobStat).toEqual(
369-
0,
370-
);
379+
expect(bobStat).toEqual(0);
371380
});
372381
});
373382

@@ -388,9 +397,7 @@ describe("DeviceList management:", function() {
388397
const bobStat = data!.trackingStatus['@bob:xyz'];
389398

390399
// Alice should have marked bob's device list as untracked
391-
expect(bobStat).toEqual(
392-
0,
393-
);
400+
expect(bobStat).toEqual(0);
394401
});
395402
} finally {
396403
anotherTestClient.stop();

0 commit comments

Comments
 (0)