Skip to content

Commit 8bac620

Browse files
committed
[ts] enable "resolveJsonModule" and disable existing failures
1 parent dffd631 commit 8bac620

File tree

31 files changed

+69
-36
lines changed

31 files changed

+69
-36
lines changed

tsconfig.base.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
// Resolve modules in the same way as Node.js. Aka make `require` works the
4040
// same in TypeScript as it does in Node.js.
4141
"moduleResolution": "node",
42+
// "resolveJsonModule" allows for importing, extracting types from and generating .json files.
43+
"resolveJsonModule": true,
4244
// Disallow inconsistently-cased references to the same file.
4345
"forceConsistentCasingInFileNames": true,
4446
// Forbid unused local variables as the rule was deprecated by ts-lint

typings/index.d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ declare module '*.svg' {
3535
export default content;
3636
}
3737

38-
// allow JSON files to be imported directly without lint errors
39-
// see: https://github.com/palantir/tslint/issues/1264#issuecomment-228433367
40-
// and: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#arbitrary-expressions-are-forbidden-in-export-assignments-in-ambient-contexts
41-
declare module '*.json' {
42-
const json: any;
43-
// eslint-disable-next-line import/no-default-export
44-
export default json;
45-
}
46-
4738
type MethodKeysOf<T> = {
4839
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
4940
}[keyof T];

x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/__test__/List.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('ErrorGroupOverview -> List', () => {
4343
<MemoryRouter>
4444
<MockApmPluginContextWrapper>
4545
<MockUrlParamsContextProvider>
46+
{/* @ts-expect-error invalid json props */}
4647
<ErrorGroupList items={props.items} serviceName="opbeans-python" />
4748
</MockUrlParamsContextProvider>
4849
</MockApmPluginContextWrapper>

x-pack/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverTransactionButton.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import mockTransaction from './mockTransaction.json';
1515

1616
describe('DiscoverTransactionLink component', () => {
1717
it('should render with data', () => {
18+
// @ts-expect-error invalid json mock
1819
const transaction: Transaction = mockTransaction;
1920

2021
expect(
@@ -25,6 +26,7 @@ describe('DiscoverTransactionLink component', () => {
2526

2627
describe('getDiscoverQuery', () => {
2728
it('should return the correct query params object', () => {
29+
// @ts-expect-error invalid json mock
2830
const transaction: Transaction = mockTransaction;
2931
const result = getDiscoverQuery(transaction);
3032
expect(result).toMatchSnapshot();

x-pack/plugins/apm/server/lib/service_map/group_resource_nodes.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import expectedGroupedData from './mock_responses/group_resource_nodes_grouped.j
1010

1111
describe('groupResourceNodes', () => {
1212
it('should group external nodes', () => {
13+
// @ts-expect-error invalid json mock
1314
const responseWithGroups = groupResourceNodes(preGroupedData);
1415
expect(responseWithGroups.elements).toHaveLength(
1516
expectedGroupedData.elements.length
1617
);
1718
for (const element of responseWithGroups.elements) {
1819
const expectedElement = expectedGroupedData.elements.find(
1920
({ data: { id } }: { data: { id: string } }) => id === element.data.id
20-
);
21+
)!;
2122
expect(element).toMatchObject(expectedElement);
2223
}
2324
});

x-pack/plugins/apm/server/lib/services/annotations/index.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('getServiceAnnotations', () => {
3131
searchAggregatedTransactions: false,
3232
}),
3333
{
34+
// @ts-expect-error invalid json mock
3435
mockResponse: () => noVersions,
3536
}
3637
);
@@ -50,6 +51,7 @@ describe('getServiceAnnotations', () => {
5051
searchAggregatedTransactions: false,
5152
}),
5253
{
54+
// @ts-expect-error invalid json mock
5355
mockResponse: () => oneVersion,
5456
}
5557
);
@@ -74,6 +76,7 @@ describe('getServiceAnnotations', () => {
7476
searchAggregatedTransactions: false,
7577
}),
7678
{
79+
// @ts-expect-error invalid json mock
7780
mockResponse: () => responses.shift(),
7881
}
7982
);

x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function demodata(): ExpressionFunctionDefinition<
6161
{ id: 'project', name: 'project', meta: { type: 'string' } },
6262
{ id: 'percent_uptime', name: 'percent_uptime', meta: { type: 'number' } },
6363
],
64+
// @ts-expect-error invalid json mock
6465
rows: sortBy(demoRows, 'time'),
6566
};
6667
} else if (args.type === DemoRows.SHIRTS) {

x-pack/plugins/canvas/shareable_runtime/components/__tests__/app.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
/*
8-
One test relies on react-dom at a version of 16.9... it can be enabled
9-
once renovate completes the upgrade. Relevant code has been commented out
10-
in the meantime.
7+
/*
8+
One test relies on react-dom at a version of 16.9... it can be enabled
9+
once renovate completes the upgrade. Relevant code has been commented out
10+
in the meantime.
1111
*/
1212

1313
import { mount, ReactWrapper } from 'enzyme';

x-pack/plugins/canvas/shareable_runtime/test/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ import test from './workpads/test.json';
1111
export * from './utils';
1212

1313
export type WorkpadNames = keyof typeof sharedWorkpads;
14-
export const sharedWorkpads = { hello, austin, test };
14+
export const sharedWorkpads = {
15+
// TODO: the automatic types for these JSON files are insufficient, and "austin" is so massive
16+
// that Typescript refuses to type it. These should be converted to TypeScript and typed to fit
17+
// the requirements. "austin" should also be reduced to the necessary data
18+
hello: hello as any,
19+
austin: austin as any,
20+
test: test as any,
21+
};

x-pack/plugins/infra/public/utils/apollo_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const createApolloClient = (fetch: HttpHandler) => {
1616
const cache = new InMemoryCache({
1717
addTypename: false,
1818
fragmentMatcher: new IntrospectionFragmentMatcher({
19+
// @ts-expect-error apollo-cache-inmemory types don't match actual introspection data
1920
introspectionQueryResultData,
2021
}),
2122
});

0 commit comments

Comments
 (0)