Skip to content

Commit

Permalink
chore(ts): avoid more ts-ignores (algolia#4817)
Browse files Browse the repository at this point in the history
ts-expect-error will error if it's no longer needed, so it's better in almost all cases. There's some moments where we need to keep ts-ignore though:
- things that fail only with algoliasearch v3 or v4
- optional packages (places)
- code that doesn't always error

At the same time updated the algoliasearch-helper to a version that includes `showParentLevel` in the typings
  • Loading branch information
Haroenv authored Jul 30, 2021
1 parent 16cc341 commit 21b6c53
Show file tree
Hide file tree
Showing 29 changed files with 251 additions and 213 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@types/google.maps": "^3.45.3",
"@types/hogan.js": "^3.0.0",
"@types/qs": "^6.5.3",
"algoliasearch-helper": "^3.5.4",
"algoliasearch-helper": "^3.5.5",
"classnames": "^2.2.5",
"events": "^1.1.0",
"hogan.js": "^3.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/connectors/answers/__tests__/connectAnswers-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('connectAnswers', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore: test connectAnswers with invalid parameters
// @ts-expect-error: test connectAnswers with invalid parameters
connectAnswers()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand All @@ -27,7 +27,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/answers/js/

it('throws without `queryLanguages`', () => {
expect(() => {
// @ts-ignore: test connectAnswers with invalid parameters
// @ts-expect-error: test connectAnswers with invalid parameters
connectAnswers(() => {})({});
}).toThrowErrorMatchingInlineSnapshot(`
"The \`queryLanguages\` expects an array of strings.
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/answers/connectAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const connectAnswers: AnswersConnector = function connectAnswers(
extraParameters = {},
} = widgetParams || {};

// @ts-ignore checking for the wrong value
// @ts-expect-error checking for the wrong value
if (!queryLanguages || queryLanguages.length === 0) {
throw new Error(
withUsage('The `queryLanguages` expects an array of strings.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import connectAutocomplete, {
AutocompleteRenderState,
} from '../connectAutocomplete';
import { TAG_PLACEHOLDER } from '../../../lib/utils';
import { Hit, SearchClient } from '../../../types';
import { EscapedHits, Hit, SearchClient } from '../../../types';

describe('connectAutocomplete', () => {
const getInitializedWidget = (config = {}) => {
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('connectAutocomplete', () => {

it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectAutocomplete();
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand All @@ -56,7 +56,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/autocomplet

const trigger = () => {
makeWidget({
// @ts-ignore outdated `indices` option
// @ts-expect-error outdated `indices` option
indices: [
{ label: 'Products', value: 'products' },
{ label: 'Services', value: 'services' },
Expand Down Expand Up @@ -535,8 +535,7 @@ search.addWidgets([
);

const hits: Hit[] = [];
// @ts-ignore-next-line
hits.__escaped = true;
(hits as EscapedHits).__escaped = true;

expect(renderState).toEqual({
currentRefinement: 'query',
Expand Down
10 changes: 2 additions & 8 deletions src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('connectBreadcrumb', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectBreadcrumb()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand All @@ -28,7 +28,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
it('throws with undefined `attributes`', () => {
expect(() => {
connectBreadcrumb(() => {})({
// @ts-ignore
// @ts-expect-error
attributes: undefined,
});
}).toThrowErrorMatchingInlineSnapshot(`
Expand Down Expand Up @@ -368,8 +368,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
name: 'category',
attributes: ['category', 'sub_category'],
separator: ' > ',
// @TODO Add missing type to js helper
// @ts-ignore
rootPath: null,
},
],
Expand Down Expand Up @@ -402,7 +400,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
name: 'category',
attributes: ['category', 'sub_category', 'sub_sub_category'],
separator: ' > ',
// @ts-ignore
rootPath: null,
},
],
Expand All @@ -428,7 +425,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
name: 'category',
attributes: ['category', 'sub_category'],
separator: ' > ',
// @ts-ignore
rootPath: null,
},
],
Expand All @@ -455,7 +451,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
name: 'category',
attributes: ['category', 'sub_category'],
separator: ' > ',
// @ts-ignore
rootPath: 'TopLevel > SubLevel',
},
],
Expand Down Expand Up @@ -488,7 +483,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/breadcrumb/
{
attributes: ['category', 'sub_category'],
name: 'category',
// @ts-ignore
rootPath: null,
separator: ' > ',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('connectClearRefinements', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectClearRefinements()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('connectConfigureRelatedItems', () => {
const configureRelatedItems = connectConfigureRelatedItems(noop);

expect(() => {
// @ts-ignore missing options
// @ts-expect-error missing options
configureRelatedItems();
}).toThrowErrorMatchingInlineSnapshot(`
"The \`hit\` option is required.
Expand All @@ -54,7 +54,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure-r
const configureRelatedItems = connectConfigureRelatedItems(noop);

expect(() => {
// @ts-ignore missing options
// @ts-expect-error missing options
configureRelatedItems({
hit,
});
Expand Down
10 changes: 5 additions & 5 deletions src/connectors/configure/__tests__/connectConfigure-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('connectConfigure', () => {

describe('Usage', () => {
it('throws without searchParameters', () => {
// @ts-ignore wrong options
// @ts-expect-error wrong options
expect(() => connectConfigure()()).toThrowErrorMatchingInlineSnapshot(`
"The \`searchParameters\` option expects an object.
Expand All @@ -31,7 +31,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure/j

it('throws when you pass it a non-plain object', () => {
expect(() => {
// @ts-ignore wrong options
// @ts-expect-error wrong options
connectConfigure()(new Date());
}).toThrowErrorMatchingInlineSnapshot(`
"The \`searchParameters\` option expects an object.
Expand All @@ -40,7 +40,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure/j
`);

expect(() => {
// @ts-ignore wrong options
// @ts-expect-error wrong options
connectConfigure()(() => {});
}).toThrowErrorMatchingInlineSnapshot(`
"The \`searchParameters\` option expects an object.
Expand All @@ -54,12 +54,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure/j
});

it('with a unmount function but no render function does not throw', () => {
// @ts-ignore wrong options
// @ts-expect-error wrong options
expect(() => connectConfigure(undefined, jest.fn())).not.toThrow();
});

it('does not throw without render and unmount functions', () => {
// @ts-ignore wrong options
// @ts-expect-error wrong options
expect(() => connectConfigure(undefined, undefined)).not.toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
name: 'category',
rootPath: null,
separator: ' > ',
// @ts-ignore `showParentLevel` is missing in the SearchParameters.HierarchicalFacet declaration
showParentLevel: true,
},
],
Expand Down Expand Up @@ -918,7 +917,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
attributes: ['categoriesLvl0', 'categoriesLvl1'],
separator: ' > ',
rootPath: null,
// @ts-ignore `showParentLevel` is missing in the SearchParameters.HierarchicalFacet declaration
showParentLevel: true,
},
],
Expand Down Expand Up @@ -956,7 +954,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
attributes: ['categoriesLvl0', 'categoriesLvl1'],
separator: ' > ',
rootPath: null,
// @ts-ignore `showParentLevel` is missing in the SearchParameters.HierarchicalFacet declaration
showParentLevel: true,
},
],
Expand Down Expand Up @@ -1182,7 +1179,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
uiState: {},
});

// @ts-ignore `showParentLevel` is missing in the SearchParameters.HierarchicalFacet declaration
expect(actual.hierarchicalFacets[0].showParentLevel).toBe(true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ const connectHierarchicalMenu: HierarchicalMenuConnector = function connectHiera
attributes,
separator,
rootPath,
// @ts-ignore `showParentLevel` is missing in the SearchParameters.HierarchicalFacet declaration
showParentLevel,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('connectHitsPerPage', () => {
it('throws without items', () => {
expect(() => {
connectHitsPerPage(() => {})({
// @ts-ignore
// @ts-expect-error
items: undefined,
});
}).toThrowErrorMatchingInlineSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/hits/__tests__/connectHits-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock('../../../lib/utils/hits-absolute-position', () => ({
describe('connectHits', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectHits()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('connectHitsWithInsights', () => {

it('does not throw without the unmount function', () => {
const rendering = () => {};
// @ts-ignore:next-line
const makeWidget = connectHitsWithInsights(rendering);
const widget = makeWidget({});
const helper = algoliasearchHelper(createSearchClient(), '', {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jest.mock('../../../lib/utils/hits-absolute-position', () => ({
describe('connectInfiniteHits', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore: test connectInfiniteHits with invalid parameters
// @ts-expect-error: test connectInfiniteHits with invalid parameters
connectInfiniteHits()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('connectInfiniteHitsWithInsights', () => {

it('does not throw without the unmount function', () => {
const rendering = () => {};
// @ts-ignore:next-line
const makeWidget = connectInfiniteHitsWithInsights(rendering);
const helper = algoliasearchHelper(createSearchClient(), '', {});
const widget = makeWidget({});
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/menu/__tests__/connectMenu-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('connectMenu', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectMenu()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('connectNumericMenu', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectNumericMenu()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand All @@ -69,7 +69,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men

it('throws without attribute', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectNumericMenu(() => {})({ attribute: undefined, items: [] });
}).toThrowErrorMatchingInlineSnapshot(`
"The \`attribute\` option is required.
Expand All @@ -82,7 +82,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/numeric-men
expect(() => {
connectNumericMenu(() => {})({
attribute: 'attribute',
// @ts-ignore
// @ts-expect-error
items: undefined,
});
}).toThrowErrorMatchingInlineSnapshot(`
Expand Down
6 changes: 3 additions & 3 deletions src/connectors/pagination/__tests__/connectPagination-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('connectPagination', () => {
describe('Usage', () => {
it('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectPagination()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down Expand Up @@ -70,7 +70,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/pagination/
const renderFn = jest.fn();
const makeWidget = connectPagination(renderFn);
const widget = makeWidget({
// @ts-ignore
// @ts-expect-error
foo: 'bar',
});

Expand Down Expand Up @@ -614,7 +614,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/pagination/
widget.getRenderState(
{
hierarchicalMenu: {},
// @ts-ignore
// @ts-expect-error
pagination: {},
},
createRenderOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import connectPoweredBy from '../connectPoweredBy';
describe('connectPoweredBy', () => {
it('throws without rendering function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectPoweredBy();
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('connectQueryRules', () => {
describe('usage', () => {
test('throws without render function', () => {
expect(() => {
// @ts-ignore
// @ts-expect-error
connectQueryRules()({});
}).toThrowErrorMatchingInlineSnapshot(`
"The render function is not valid (received type Undefined).
Expand All @@ -55,7 +55,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/query-rules
expect(() => {
const { makeWidget } = createWidget();
makeWidget({
// @ts-ignore
// @ts-expect-error
trackedFilters: { brand: ['Samsung'] },
});
}).toThrowErrorMatchingInlineSnapshot(`
Expand Down
Loading

0 comments on commit 21b6c53

Please sign in to comment.