Skip to content

fix: Add noUncheckedIndexAccess to tsconfig #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/isograph-react/src/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function normalizeLinkedField(
const dataIds: (Link | null)[] = [];
for (let i = 0; i < networkResponseData.length; i++) {
const networkResponseObject = networkResponseData[i];
if (networkResponseObject === null) {
if (networkResponseObject == null) {
dataIds.push(null);
continue;
}
Expand Down
27 changes: 20 additions & 7 deletions libs/isograph-react/src/core/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,12 @@ function readData<TReadFromStore>(
};
} else {
const refetchQueryIndex = field.refetchQuery;
if (refetchQueryIndex == null) {
throw new Error('refetchQuery is null in RefetchField');
}
const refetchQuery = nestedRefetchQueries[refetchQueryIndex];
if (refetchQuery == null) {
throw new Error(
'refetchQuery is null in RefetchField. This is indicative of a bug in Isograph.',
);
}
const refetchQueryArtifact = refetchQuery.artifact;
const allowedVariables = refetchQuery.allowedVariables;

Expand All @@ -371,9 +373,15 @@ function readData<TReadFromStore>(
}
case 'Resolver': {
const usedRefetchQueries = field.usedRefetchQueries;
const resolverRefetchQueries = usedRefetchQueries.map(
(index) => nestedRefetchQueries[index],
);
const resolverRefetchQueries = usedRefetchQueries.map((index) => {
const resolverRefetchQuery = nestedRefetchQueries[index];
if (resolverRefetchQuery == null) {
throw new Error(
'resolverRefetchQuery is null in Resolver. This is indicative of a bug in Isograph.',
);
}
return resolverRefetchQuery;
});

switch (field.readerArtifact.kind) {
case 'EagerReaderArtifact': {
Expand Down Expand Up @@ -636,7 +644,12 @@ function generateChildVariableMap(
const childVars: Writable<Variables> = {};
for (const [name, value] of fieldArguments) {
if (value.kind === 'Variable') {
childVars[name] = variables[value.name];
const variable = variables[value.name];
// Variable could be null if it was not provided but has a default case,
// so we allow the loop to continue rather than throwing an error.
if (variable != null) {
childVars[name] = variable;
}
} else {
childVars[name] = value.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ export function useConnectionSpecPagination<
fragmentReference.readerWithRefetchQueries,
);

// invariant: readOutDataAndRecords.length === completedReferences.length
const data = readOutDataAndRecords[i]?.item;
if (data == null) {
throw new Error(
'Parameter data is unexpectedly null. This is indicative of a bug in Isograph.',
);
}

const firstParameter = {
data: readOutDataAndRecords[i].item,
data,
parameters: fragmentReference.variables,
};

Expand Down Expand Up @@ -165,10 +173,17 @@ export function useConnectionSpecPagination<
fragmentReference.readerWithRefetchQueries,
);

const records = readOutDataAndRecords[i];
if (records == null) {
throw new Error(
'subscribeCompletedFragmentReferences records is unexpectedly null',
);
}

return {
fragmentReference,
readerAst: readerWithRefetchQueries.readerArtifact.readerAst,
records: readOutDataAndRecords[i],
records,
callback(_data) {
rerender({});
},
Expand Down Expand Up @@ -224,10 +239,9 @@ export function useConnectionSpecPagination<

const loadedReferences = state === UNASSIGNED_STATE ? [] : state;

const mostRecentItem: LoadedFragmentReference<
TReadFromStore,
Connection<TItem>
> | null = loadedReferences[loadedReferences.length - 1];
const mostRecentItem:
| LoadedFragmentReference<TReadFromStore, Connection<TItem>>
| undefined = loadedReferences[loadedReferences.length - 1];
const mostRecentFragmentReference =
mostRecentItem?.[0].getItemIfNotDisposed();

Expand Down
24 changes: 20 additions & 4 deletions libs/isograph-react/src/loadable-hooks/useSkipLimitPagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ export function useSkipLimitPagination<
fragmentReference.readerWithRefetchQueries,
);

// invariant: readOutDataAndRecords.length === completedReferences.length
const data = readOutDataAndRecords[i]?.item;
if (data == null) {
throw new Error(
'Parameter data is unexpectedly null. This is indicative of a bug in Isograph.',
);
}

const firstParameter = {
data: readOutDataAndRecords[i].item,
data,
parameters: fragmentReference.variables,
};

Expand Down Expand Up @@ -150,10 +158,17 @@ export function useSkipLimitPagination<
fragmentReference.readerWithRefetchQueries,
);

const records = readOutDataAndRecords[i];
if (records == null) {
throw new Error(
'subscribeCompletedFragmentReferences records is unexpectedly null',
);
}

return {
fragmentReference,
readerAst: readerWithRefetchQueries.readerArtifact.readerAst,
records: readOutDataAndRecords[i],
records,
callback(_data) {
rerender({});
},
Expand Down Expand Up @@ -209,8 +224,9 @@ export function useSkipLimitPagination<

const loadedReferences = state === UNASSIGNED_STATE ? [] : state;

const mostRecentItem: LoadedFragmentReference<TReadFromStore, TItem> | null =
loadedReferences[loadedReferences.length - 1];
const mostRecentItem:
| LoadedFragmentReference<TReadFromStore, TItem>
| undefined = loadedReferences[loadedReferences.length - 1];
const mostRecentFragmentReference =
mostRecentItem?.[0].getItemIfNotDisposed();

Expand Down
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"noPropertyAccessFromIndexSignature": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noUncheckedIndexedAccess": true,
"paths": {
"@isograph/*": ["./libs/*"]
},
Expand Down
Loading