Skip to content

Commit cc0582b

Browse files
authored
ref: set useUnknownInCatchVariables to true in tsconfig (#97665)
Note: all changes here are on type-level only - there are no runtime changes. Most things have been addressed by setting error explicitly to `any`. In some simple cases, a type assertion was done. Tests have been changed from try/catch to the `.toThrow` assertion. This change slightly increases type coverage, as there are many situations where error is now `unknown` instead of `any`:   | Total Symbols | Covered Symbols | Uncovered Symbols | Symbol Diff | Coverage Percentage | % Diff -- | -- | -- | -- | -- | -- | -- before | 1,454,893 | 1,394,217 | 60,676 |   | 95.82% |   after | 1,454,922 | 1,394,596 | 60,326 | -350 | 95.85% | +0.03%
1 parent 3670ef6 commit cc0582b

File tree

102 files changed

+175
-181
lines changed

Some content is hidden

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

102 files changed

+175
-181
lines changed

config/tsconfig.base.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@
4040
"noUncheckedIndexedAccess": true,
4141
"strict": true,
4242
"strictBindCallApply": false,
43-
"useUnknownInCatchVariables": false,
44-
43+
"useUnknownInCatchVariables": true,
4544
// We do not configure these, but are left here for documentation purposes
4645
//
4746
// allowUnreachableCode
4847
// allowUnusedLabels
4948
// exactOptionalPropertyTypes
5049
// noImplicitOverride
5150
// noPropertyAccessFromIndexSignature
52-
// noUncheckedIndexedAccess
5351
// strictFunctionTypes
5452
// strictNullChecks
5553
// strictPropertyInitialization
56-
// anduseUnknownInCatchVariables
5754

5855
// Emit configuration
5956
"declaration": false,

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if (CI && !process.env.JEST_LIST_TESTS_INNER) {
7575
env: {...process.env, JEST_LIST_TESTS_INNER: '1'},
7676
});
7777
JEST_TESTS = JSON.parse(stdout);
78-
} catch (err) {
78+
} catch (err: any) {
7979
if (err.code) {
8080
throw new Error(`err code ${err.code} when spawning process`);
8181
} else {

static/app/actionCreators/dashboards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export async function updateDashboardFavorite(
125125
queryKey: getQueryKey(organization),
126126
});
127127
addSuccessMessage(isFavorited ? t('Added as favorite') : t('Removed as favorite'));
128-
} catch (response) {
128+
} catch (response: any) {
129129
const errorResponse = response?.responseJSON ?? null;
130130
if (errorResponse) {
131131
const errors = flattenErrors(errorResponse, {});

static/app/actionCreators/guides.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function fetchGuides() {
2323
}
2424
const data = await api.requestPromise('/assistant/');
2525
GuideStore.fetchSucceeded(data);
26-
} catch (err) {
26+
} catch (err: any) {
2727
if (err.status !== 401 && err.status !== 403) {
2828
Sentry.captureException(err);
2929
}

static/app/actionCreators/monitors.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function updateMonitor(
6464
);
6565
clearIndicators();
6666
return resp;
67-
} catch (err) {
67+
} catch (err: any) {
6868
const respError: RequestError = err;
6969
const updateKeys = Object.keys(data);
7070

@@ -165,7 +165,7 @@ export async function deleteMonitorProcessingErrorByType(
165165
}
166166
);
167167
clearIndicators();
168-
} catch (err) {
168+
} catch (err: any) {
169169
Sentry.captureException(err);
170170
if (err.status === 403) {
171171
addErrorMessage(t('You do not have permission to dismiss these processing errors'));
@@ -189,7 +189,7 @@ export async function deleteProjectProcessingErrorByType(
189189
query: {errortype},
190190
});
191191
clearIndicators();
192-
} catch (err) {
192+
} catch (err: any) {
193193
Sentry.captureException(err);
194194
if (err.status === 403) {
195195
addErrorMessage(t('You do not have permission to dismiss these processing errors'));

static/app/actionCreators/organization.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function fetchProjectsAndTeams(
6868

6969
try {
7070
return await Promise.all([projectsPromise, teamsPromise]);
71-
} catch (err) {
71+
} catch (err: any) {
7272
// It's possible these requests fail with a 403 if the user has a role with
7373
// insufficient access to projects and teams, but *can* access org details
7474
// (e.g. billing). An example of this is in org settings.
@@ -106,7 +106,7 @@ export async function fetchOrganizationDetails(api: Client, slug: string): Promi
106106
let org: Organization | undefined = undefined;
107107
try {
108108
org = await fetchOrg(api, slug);
109-
} catch (err) {
109+
} catch (err: any) {
110110
if (!err) {
111111
throw err;
112112
}

static/app/actionCreators/performance.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function fetchTeamKeyTransactions(
5858
} else {
5959
hasMore = false;
6060
}
61-
} catch (err) {
61+
} catch (err: any) {
6262
addErrorMessage(
6363
err.responseJSON?.detail ?? t('Error fetching team key transactions')
6464
);

static/app/actionCreators/uptime.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function updateUptimeRule(
2626
clearIndicators();
2727
return resp;
2828
} catch (err) {
29-
const respError: RequestError = err;
29+
const respError = err as RequestError;
3030
const updateKeys = Object.keys(data);
3131

3232
// If we are updating a single value in the monitor we can read the

static/app/api.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ export class Client {
553553
// Try to get text out of the response no matter the status
554554
try {
555555
responseText = await response.text();
556-
} catch (error) {
556+
} catch (error: any) {
557557
twoHundredErrorReason = 'Failed awaiting response.text()';
558558
ok = false;
559559
if (error.name === 'AbortError') {
@@ -572,7 +572,7 @@ export class Client {
572572
if (status !== 204 && !isStatus3XX) {
573573
try {
574574
responseJSON = JSON.parse(responseText);
575-
} catch (error) {
575+
} catch (error: any) {
576576
twoHundredErrorReason = 'Failed trying to parse responseText';
577577
if (error.name === 'AbortError') {
578578
ok = false;

static/app/bootstrap/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function promiseRequest(url: string) {
6969
}
7070
// eslint-disable-next-line no-throw-literal
7171
throw [response.status, response.statusText];
72-
} catch (error) {
72+
} catch (error: any) {
7373
// eslint-disable-next-line no-throw-literal
7474
throw [error.status, error.statusText];
7575
}

0 commit comments

Comments
 (0)