Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
chore(NA): enables isolatedModules on base tsconfig file (elastic#144841
Browse files Browse the repository at this point in the history
)

This PR enables `isolatedModules` on our `tsconfig.base.json`. Enabling
this means that our codebase is safe for tools that use TypeScript APIs
like `transpileModule` or alternative compilers like Babel. The
requirements introduced by enabling `isolatedModules` were already in
place for every piece of code transpiled with babel so we feel like its
time to make it the default across the board inside our repository.

The DX shouldn't be impacted negatively by these change as we introduced
a lint rule verification for the critical part around `isolatedModules`
which is around `const enums`. The PR also has a couple of `TODOs` to be
removed once we upgrade into typescript v4.8 where we would be able to
say everything that is typescript inside our repo should be consider a
module by default.

More information about `isolatedModules` can be found at
https://www.typescriptlang.org/tsconfig#isolatedModules

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
mistic and kibanamachine authored Nov 18, 2022
1 parent 9a0622b commit 016e3e0
Show file tree
Hide file tree
Showing 68 changed files with 174 additions and 120 deletions.
22 changes: 10 additions & 12 deletions packages/content-management/inspector/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ ts_project(
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
Expand All @@ -124,6 +123,14 @@ js_library(
visibility = ["//visibility:public"],
)

js_library(
name = "npm_module_types",
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
Expand All @@ -135,17 +142,8 @@ filegroup(
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
pkg_npm(
name = "build_types",
srcs = [":npm_module_types"],
deps = [":npm_module_types"],
visibility = ["//visibility:public"],
)
3 changes: 2 additions & 1 deletion packages/content-management/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
"license": "SSPL-1.0 OR Elastic License 2.0",
"types": "./target_types/index.d.ts"
}
4 changes: 1 addition & 3 deletions packages/content-management/inspector/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"extends": "../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node",
Expand All @@ -17,6 +15,6 @@
},
"include": [
"**/*.ts",
"**/*.tsx",
"**/*.tsx",
]
}
9 changes: 8 additions & 1 deletion packages/kbn-eslint-config/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ module.exports = {
'import/no-default-export': 'error',

'eslint-comments/no-unused-disable': 'error',
'eslint-comments/no-unused-enable': 'error'
'eslint-comments/no-unused-enable': 'error',
'no-restricted-syntax': [
'error',
{
"selector": "TSEnumDeclaration[const=true]",
"message": "Do not use `const` with enum declarations"
}
]
},
eslintConfigPrettierRules
)
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-optimizer/src/worker/entry_point_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Side Public License, v 1.
*/

// TODO: we should be able to remove this ts-ignore while using isolatedModules
// this is a skip for the errors created when typechecking with isolatedModules
// @ts-ignore
module.exports = function ({
entries,
}: {
Expand Down
7 changes: 0 additions & 7 deletions packages/kbn-securitysolution-list-hooks/src/use_api/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const FILEPATH_WARNING = i18n.translate('utils.filename.pathWarning', {
defaultMessage: `Path may be formed incorrectly; verify value`,
});

export const enum ConditionEntryField {
export enum ConditionEntryField {
HASH = 'process.hash.*',
PATH = 'process.executable.caseless',
SIGNER = 'process.Ext.code_signature',
}

export const enum EntryFieldType {
export enum EntryFieldType {
HASH = '.hash.',
EXECUTABLE = '.executable.caseless',
PATH = '.path',
Expand All @@ -39,7 +39,7 @@ export type AllConditionEntryFields =
| BlocklistConditionEntryField
| 'file.path.text';

export const enum OperatingSystem {
export enum OperatingSystem {
LINUX = 'linux',
MAC = 'macos',
WINDOWS = 'windows',
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/bfetch/public/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* Side Public License, v 1.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

jest.mock('../../../../contexts/editor_context/editor_registry', () => ({
instance: {
setInputEditor: () => {},
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/controls/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ export {
} from '../common';

export {
ControlGroupContainer,
type ControlGroupContainer,
ControlGroupContainerFactory,
type ControlGroupInput,
type ControlGroupOutput,
} from './control_group';

export {
OptionsListEmbeddableFactory,
OptionsListEmbeddable,
type OptionsListEmbeddable,
type OptionsListEmbeddableInput,
} from './options_list';

export {
RangeSliderEmbeddableFactory,
RangeSliderEmbeddable,
type RangeSliderEmbeddable,
type RangeSliderEmbeddableInput,
} from './range_slider';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export type { DefaultFormatEditor } from './default';
export type { FieldFormatEditor, FieldFormatEditorFactory, FormatEditorProps } from './types';
export type { UrlFormatEditorFormatParams } from './url';

export { BytesFormatEditor, bytesFormatEditorFactory } from './bytes';
export { ColorFormatEditor, colorFormatEditorFactory } from './color';
export { DateFormatEditor, dateFormatEditorFactory } from './date';
export { DateNanosFormatEditor, dateNanosFormatEditorFactory } from './date_nanos';
export { type BytesFormatEditor, bytesFormatEditorFactory } from './bytes';
export { type ColorFormatEditor, colorFormatEditorFactory } from './color';
export { type DateFormatEditor, dateFormatEditorFactory } from './date';
export { type DateNanosFormatEditor, dateNanosFormatEditorFactory } from './date_nanos';
export { defaultFormatEditorFactory } from './default';
export { DurationFormatEditor, durationFormatEditorFactory } from './duration';
export { GeoPointFormatEditor, geoPointFormatEditorFactory } from './geo_point';
export { HistogramFormatEditor, histogramFormatEditorFactory } from './histogram';
export { NumberFormatEditor, numberFormatEditorFactory } from './number';
export { PercentFormatEditor, percentFormatEditorFactory } from './percent';
export { StaticLookupFormatEditor, staticLookupFormatEditorFactory } from './static_lookup';
export { StringFormatEditor, stringFormatEditorFactory } from './string';
export { TruncateFormatEditor, truncateFormatEditorFactory } from './truncate';
export { UrlFormatEditor, urlFormatEditorFactory } from './url';
export { type DurationFormatEditor, durationFormatEditorFactory } from './duration';
export { type GeoPointFormatEditor, geoPointFormatEditorFactory } from './geo_point';
export { type HistogramFormatEditor, histogramFormatEditorFactory } from './histogram';
export { type NumberFormatEditor, numberFormatEditorFactory } from './number';
export { type PercentFormatEditor, percentFormatEditorFactory } from './percent';
export { type StaticLookupFormatEditor, staticLookupFormatEditorFactory } from './static_lookup';
export { type StringFormatEditor, stringFormatEditorFactory } from './string';
export { type TruncateFormatEditor, truncateFormatEditorFactory } from './truncate';
export { type UrlFormatEditor, urlFormatEditorFactory } from './url';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

// TODO: implement this on the server

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

// import { StartServicesAccessor } from '@kbn/core/server';
// import { EventAnnotationStartDependencies } from '../plugin';

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/expressions/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ export type {
export {
buildExpression,
buildExpressionFunction,
Execution,
Executor,
type Execution,
type Executor,
ExpressionFunction,
ExpressionFunctionParameter,
type ExpressionFunctionParameter,
ExpressionRenderer,
ExpressionRendererRegistry,
type ExpressionRendererRegistry,
ExpressionType,
FontStyle,
FontWeight,
format,
formatExpression,
FunctionsRegistry,
type FunctionsRegistry,
isExpressionAstBuilder,
Overflow,
parse,
parseExpression,
TextAlignment,
TextDecoration,
TypesRegistry,
type TypesRegistry,
} from '../common';
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
import { ExpressionsStart, ExpressionRenderHandler } from '@kbn/expressions-plugin/public';
import { Adapters } from '@kbn/inspector-plugin/public';

export type { ExpressionsStart, Adapters };
export { ExpressionRenderHandler };
export type { ExpressionsStart, ExpressionRenderHandler, Adapters };
7 changes: 7 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,13 @@
"strict": true,
// for now, don't use unknown in catch
"useUnknownInCatchVariables": false,
// enabled to point out not supported features when emitting in an isolated module environment
"isolatedModules": true,
// TODO(jbudz): should be uncommented when upgrading to [email protected]
//
// ensures every non-declaration file is treated as a module
// "moduleDetection": "force",
//
// disabled for better IDE support, enabled when running the type_check script
"composite": false,
// enabled for improved performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

export const enum ApmMlDetectorType {
export enum ApmMlDetectorType {
txLatency = 'txLatency',
txThroughput = 'txThroughput',
txFailureRate = 'txFailureRate',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/common/privilege_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as t from 'io-ts';

export const enum PrivilegeType {
export enum PrivilegeType {
EVENT = 'event:write',
AGENT_CONFIG = 'config_agent:read',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { euiPaletteColorBlind } from '@elastic/eui';

export const enum ChartType {
export enum ChartType {
LATENCY_AVG,
LATENCY_P95,
LATENCY_P99,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/public/common/mock/match_media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

window.matchMedia = jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ interface Props {

type TagSelectableOption = EuiSelectableOption<{ tagIcon: IconType; newItem?: boolean }>;

const enum TagState {
enum TagState {
CHECKED = 'checked',
PARTIAL = 'partial',
UNCHECKED = 'unchecked',
}

const enum Actions {
enum Actions {
CHECK_TAG,
UNCHECK_TAG,
}

const enum ICONS {
enum ICONS {
CHECKED = 'check',
PARTIAL = 'asterisk',
UNCHECKED = 'empty',
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/server/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

// Careful of exporting anything from this file as any file(s) you export here will cause your functions to be exposed as public.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

jest.mock('../../../app/services/breadcrumbs', () => {
const original = jest.requireActual('../../../app/services/breadcrumbs');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

jest.mock('../../../app/services/track_ui_metric', () => {
const original = jest.requireActual('../../../app/services/track_ui_metric');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

// Need to wait for https://github.com/elastic/eui/pull/3173/
// to unit test this component
// basic interaction is covered in end-to-end tests
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/common/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ErrorCode } from './error_codes';
* Each Status string corresponds to a possible status in a request's lifecycle
*/

export const enum Status {
export enum Status {
IDLE,
LOADING,
SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

// TODO(jbudz): should be removed when upgrading to [email protected]
// this is a skip for the errors created when typechecking with isolatedModules
export {};

jest.mock('../../..', () => ({
EnginesLogic: { actions: { deleteEngine: jest.fn() } },
}));
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { MethodApi } from './method_api/method_api';
import { MethodConnector } from './method_connector/method_connector';
import { MethodCrawler } from './method_crawler/method_crawler';

export const enum IngestionMethodId {
export enum IngestionMethodId {
api = 'api',
connector = 'connector',
crawler = 'crawler',
Expand Down
Loading

0 comments on commit 016e3e0

Please sign in to comment.