Просмотр исходного кода

ref(tsc) fix nouncheckedindexedaccess (#82791)

Precursor to enabling ts noUncheckedIndexedAccess rule. The fixes here
dont impact the runtime and only add type assertions. I will followup
with a PR to do the same for getsentry before enabling the flag
Jonas 2 месяцев назад
Родитель
Сommit
cf8c5bdba7

+ 2 - 2
build-utils/sentry-instrumentation.ts

@@ -71,7 +71,7 @@ class SentryInstrumentation {
     sentry.setTag('arch', os.arch());
     sentry.setTag('arch', os.arch());
     sentry.setTag(
     sentry.setTag(
       'cpu',
       'cpu',
-      cpus?.length ? `${cpus[0].model} (cores: ${cpus.length})}` : 'N/A'
+      cpus?.length ? `${cpus[0]!.model} (cores: ${cpus.length})}` : 'N/A'
     );
     );
 
 
     this.Sentry = sentry;
     this.Sentry = sentry;
@@ -96,7 +96,7 @@ class SentryInstrumentation {
           .filter(assetName => !assetName.endsWith('.map'))
           .filter(assetName => !assetName.endsWith('.map'))
           .forEach(assetName => {
           .forEach(assetName => {
             const asset = compilation.assets[assetName];
             const asset = compilation.assets[assetName];
-            const size = asset.size();
+            const size = asset!.size();
             const file = assetName;
             const file = assetName;
             const body = JSON.stringify({
             const body = JSON.stringify({
               file,
               file,

+ 1 - 0
eslint.config.mjs

@@ -779,6 +779,7 @@ export default typescript.config([
     // corresponding configuration object where the plugin is initially included
     // corresponding configuration object where the plugin is initially included
     plugins: {
     plugins: {
       ...react.configs.flat.plugins,
       ...react.configs.flat.plugins,
+      // @ts-ignore noUncheckedIndexedAccess
       ...react.configs.flat['jsx-runtime'].plugins,
       ...react.configs.flat['jsx-runtime'].plugins,
       '@typescript-eslint': typescript.plugin,
       '@typescript-eslint': typescript.plugin,
       'react-hooks': fixupPluginRules(reactHooks),
       'react-hooks': fixupPluginRules(reactHooks),

+ 7 - 7
static/app/actionCreators/dashboards.tsx

@@ -27,7 +27,7 @@ export function fetchDashboards(api: Client, orgSlug: string) {
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!] as string);
     } else {
     } else {
       addErrorMessage(t('Unable to fetch dashboards'));
       addErrorMessage(t('Unable to fetch dashboards'));
     }
     }
@@ -73,7 +73,7 @@ export function createDashboard(
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!] as string);
     } else {
     } else {
       addErrorMessage(t('Unable to create dashboard'));
       addErrorMessage(t('Unable to create dashboard'));
     }
     }
@@ -118,7 +118,7 @@ export async function updateDashboardFavorite(
     const errorResponse = response?.responseJSON ?? null;
     const errorResponse = response?.responseJSON ?? null;
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!]! as string);
     } else if (isFavorited) {
     } else if (isFavorited) {
       addErrorMessage(t('Unable to favorite dashboard'));
       addErrorMessage(t('Unable to favorite dashboard'));
     } else {
     } else {
@@ -145,7 +145,7 @@ export function fetchDashboard(
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!] as string);
     } else {
     } else {
       addErrorMessage(t('Unable to load dashboard'));
       addErrorMessage(t('Unable to load dashboard'));
     }
     }
@@ -192,7 +192,7 @@ export function updateDashboard(
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!] as string);
     } else {
     } else {
       addErrorMessage(t('Unable to update dashboard'));
       addErrorMessage(t('Unable to update dashboard'));
     }
     }
@@ -218,7 +218,7 @@ export function deleteDashboard(
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!] as string);
     } else {
     } else {
       addErrorMessage(t('Unable to delete dashboard'));
       addErrorMessage(t('Unable to delete dashboard'));
     }
     }
@@ -270,7 +270,7 @@ export function updateDashboardPermissions(
 
 
     if (errorResponse) {
     if (errorResponse) {
       const errors = flattenErrors(errorResponse, {});
       const errors = flattenErrors(errorResponse, {});
-      addErrorMessage(errors[Object.keys(errors)[0]] as string);
+      addErrorMessage(errors[Object.keys(errors)[0]!]! as string);
     } else {
     } else {
       addErrorMessage(t('Unable to update dashboard permissions'));
       addErrorMessage(t('Unable to update dashboard permissions'));
     }
     }

+ 1 - 1
static/app/actionCreators/members.tsx

@@ -67,7 +67,7 @@ export function indexMembersByProject(members: Member[]): IndexedMembersByProjec
         acc[project] = [];
         acc[project] = [];
       }
       }
       if (member.user) {
       if (member.user) {
-        acc[project].push(member.user);
+        acc[project]!.push(member.user);
       }
       }
     }
     }
     return acc;
     return acc;

+ 1 - 1
static/app/actionCreators/monitors.tsx

@@ -70,7 +70,7 @@ export async function updateMonitor(
     // If we are updating a single value in the monitor we can read the
     // If we are updating a single value in the monitor we can read the
     // validation error for that key, otherwise fallback to the default error
     // validation error for that key, otherwise fallback to the default error
     const validationError =
     const validationError =
-      updateKeys.length === 1 ? respError.responseJSON?.[updateKeys[0]]?.[0] : undefined;
+      updateKeys.length === 1 ? respError.responseJSON?.[updateKeys[0]!]?.[0] : undefined;
 
 
     logException(err);
     logException(err);
     addErrorMessage(validationError ?? t('Unable to update monitor.'));
     addErrorMessage(validationError ?? t('Unable to update monitor.'));

+ 1 - 1
static/app/actionCreators/organizations.tsx

@@ -45,7 +45,7 @@ export function redirectToRemainingOrganization({
   }
   }
 
 
   // Let's be smart and select the best org to redirect to
   // Let's be smart and select the best org to redirect to
-  const firstRemainingOrg = allOrgs[0];
+  const firstRemainingOrg = allOrgs[0]!;
 
 
   const route = `/organizations/${firstRemainingOrg.slug}/issues/`;
   const route = `/organizations/${firstRemainingOrg.slug}/issues/`;
   if (USING_CUSTOMER_DOMAIN) {
   if (USING_CUSTOMER_DOMAIN) {

+ 1 - 1
static/app/actionCreators/pageFilters.tsx

@@ -319,7 +319,7 @@ export function initializeUrlState({
     if (projects && projects.length > 0) {
     if (projects && projects.length > 0) {
       // If there is a list of projects from URL params, select first project
       // If there is a list of projects from URL params, select first project
       // from that list
       // from that list
-      newProject = typeof projects === 'string' ? [Number(projects)] : [projects[0]];
+      newProject = typeof projects === 'string' ? [Number(projects)] : [projects[0]!];
     } else {
     } else {
       // When we have finished loading the organization into the props,  i.e.
       // When we have finished loading the organization into the props,  i.e.
       // the organization slug is consistent with the URL param--Sentry will
       // the organization slug is consistent with the URL param--Sentry will

+ 2 - 2
static/app/actionCreators/projects.spec.tsx

@@ -14,7 +14,7 @@ describe('Projects ActionCreators', function () {
     expect(mock).not.toHaveBeenCalled();
     expect(mock).not.toHaveBeenCalled();
 
 
     _debouncedLoadStats(api, new Set([...Array(50)].map((_, i) => String(i))), {
     _debouncedLoadStats(api, new Set([...Array(50)].map((_, i) => String(i))), {
-      projectId: project.id,
+      projectId: project!.id,
       orgId: organization.slug,
       orgId: organization.slug,
     });
     });
 
 
@@ -38,7 +38,7 @@ describe('Projects ActionCreators', function () {
     expect(mock).not.toHaveBeenCalled();
     expect(mock).not.toHaveBeenCalled();
 
 
     _debouncedLoadStats(api, new Set(['1', '2', '3']), {
     _debouncedLoadStats(api, new Set(['1', '2', '3']), {
-      projectId: project.id,
+      projectId: project!.id,
       orgId: organization.slug,
       orgId: organization.slug,
       query: {transactionStats: '1'},
       query: {transactionStats: '1'},
     });
     });

+ 3 - 3
static/app/bootstrap/initializeSdk.tsx

@@ -217,7 +217,7 @@ export function initializeSdk(config: Config) {
         images.push({
         images.push({
           type: 'sourcemap',
           type: 'sourcemap',
           code_file: filename,
           code_file: filename,
-          debug_id: debugIdMap[filename],
+          debug_id: debugIdMap[filename]!,
         });
         });
       });
       });
     } catch (e) {
     } catch (e) {
@@ -310,7 +310,7 @@ function handlePossibleUndefinedResponseBodyErrors(event: Event): void {
   const causeErrorIsURBE = causeError?.type === 'UndefinedResponseBodyError';
   const causeErrorIsURBE = causeError?.type === 'UndefinedResponseBodyError';
 
 
   if (mainErrorIsURBE || causeErrorIsURBE) {
   if (mainErrorIsURBE || causeErrorIsURBE) {
-    mainError.type = 'UndefinedResponseBodyError';
+    mainError!.type = 'UndefinedResponseBodyError';
     event.tags = {...event.tags, undefinedResponseBody: true};
     event.tags = {...event.tags, undefinedResponseBody: true};
     event.fingerprint = mainErrorIsURBE
     event.fingerprint = mainErrorIsURBE
       ? ['UndefinedResponseBodyError as main error']
       ? ['UndefinedResponseBodyError as main error']
@@ -319,7 +319,7 @@ function handlePossibleUndefinedResponseBodyErrors(event: Event): void {
 }
 }
 
 
 export function addEndpointTagToRequestError(event: Event): void {
 export function addEndpointTagToRequestError(event: Event): void {
-  const errorMessage = event.exception?.values?.[0].value || '';
+  const errorMessage = event.exception?.values?.[0]!.value || '';
 
 
   // The capturing group here turns `GET /dogs/are/great 500` into just `GET /dogs/are/great`
   // The capturing group here turns `GET /dogs/are/great 500` into just `GET /dogs/are/great`
   const requestErrorRegex = new RegExp('^([A-Za-z]+ (/[^/]+)+/) \\d+$');
   const requestErrorRegex = new RegExp('^([A-Za-z]+ (/[^/]+)+/) \\d+$');

+ 1 - 1
static/app/chartcuterie/discover.tsx

@@ -336,7 +336,7 @@ discoverCharts.push({
       const previousPeriod = LineSeries({
       const previousPeriod = LineSeries({
         name: t('previous %s', data.seriesName),
         name: t('previous %s', data.seriesName),
         data: previous.map(([_, countsForTimestamp], i) => [
         data: previous.map(([_, countsForTimestamp], i) => [
-          current[i][0] * 1000,
+          current[i]![0] * 1000,
           countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
           countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
         ]),
         ]),
         lineStyle: {color: theme.gray200, type: 'dotted'},
         lineStyle: {color: theme.gray200, type: 'dotted'},

Некоторые файлы не были показаны из-за большого количества измененных файлов